CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Question about const pointer and CCS compiler error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

Question about const pointer and CCS compiler error
PostPosted: Mon May 19, 2014 5:49 pm     Reply with quote

Hi guys.

I am using CCS compiler v5.016. I am doing some const pointer code but CCS gave a error.
I am trying to define a font structure so that once user set current font, then the display module can use a generic function to display many kinds of font on LCD. The code I define my structure and variable as below:
Code:

typedef struct _charLib  //for character library
{
   unsigned int charAmount;
   unsigned char width;
   unsigned char heigth;
   unsigned char bytePerRow;
   const unsigned char *pCharArray;
} charLib;

charArray is the font bitmap and it is defined as
Code:

const unsigned char Font1616Array[FONT1616_TOTAL_CHAR][CHAR_DOUBLE_WIDTH] =
{
   /* Character Data - Index: 0 */
   0x00,0x00,0x00,0x00,0xF0,0x3F,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0xF0,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

   /* Character Data - Index: 1 */
   0x00,0x00,0x00,0x00,0xF0,0x3F,.........
};

I just put a little part of that font array on otherwise it is too big.
Then I compile, the compiler gave me error:
*** Error 34 "C:\Project\iconCharLib.h" Line 32(31,36): Unknown type
It says in the structure define "const unsigned char *pCharArray;" is unknown type.
And if I remove "const" at both structure definition and font bitmap definition, the error gone.
I think most likely it is something stupid I make, but anyone can explain why, thanks a lot~

Kind Regards
Mark
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 19, 2014 6:28 pm     Reply with quote

In CCS, 'const' tells the compiler to store the data in Program Memory
(i.e., in Flash memory, instead of RAM). It's a good idea to declare
your font table as const, but I don't see how it helps to declare the
pointer as being stored in flash. You might want to change the pointer to
use a different font table. The pointer should be in RAM.

Anyway, I'm pretty sure we previously discussed the issue of mixing
const and RAM variables in a struct, but I can't find the thread in the
forum archives. The consensus was that the compiler doesn't support it.
So remove 'const' in the structure declaration.
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Mon May 19, 2014 9:32 pm     Reply with quote

PCM programmer wrote:
In CCS, 'const' tells the compiler to store the data in Program Memory
(i.e., in Flash memory, instead of RAM). It's a good idea to declare
your font table as const, but I don't see how it helps to declare the
pointer as being stored in flash. You might want to change the pointer to
use a different font table. The pointer should be in RAM.

Anyway, I'm pretty sure we previously discussed the issue of mixing
const and RAM variables in a struct, but I can't find the thread in the
forum archives. The consensus was that the compiler doesn't support it.
So remove 'const' in the structure declaration.

Thanks for the explanation, PCM programmer!
I remove the "const" term in structure declaration, but I got another error
Error 27 "C:\Project\iconCharLib.h" Line 916(151,152): Expression must evaluate to a constant
The error point to the code below:

Code:

charLib Font16x16 = {
      FONT1616_TOTAL_CHAR,
      16,
      16,
      2,
      Font1616Array,
};

It says "Font1616Array" expression must evaluate to a constant. I often get confused to use pointer Rolling Eyes is there anything wrong? Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 19, 2014 10:54 pm     Reply with quote

See this post by Ttelmah about declaring the array as 'rom' instead of const:
http://www.ccsinfo.com/forum/viewtopic.php?t=52298
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Tue May 20, 2014 12:16 am     Reply with quote

PCM programmer wrote:
See this post by Ttelmah about declaring the array as 'rom' instead of const:
http://www.ccsinfo.com/forum/viewtopic.php?t=52298

Thanks PCM programmer!
As the solution showed in that thread, my problem solved, and the .sym file indicates that big array move to ROM and can use pointer to point.
Next time I will do search in forum first~ Embarassed

Thanks for your kind help again.

Kind Regards
Mark
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group