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

Const array in structure

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



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

Const array in structure
PostPosted: Sat Mar 25, 2006 1:32 pm     Reply with quote

How do I build the next structure

const char test_A[1024] = {0,0,0.......};
const char test_AA[95] = {0,0,0.......};

const char test_B[1024] = {0,0,0.......};
const char test_BB[95] = {0,0,0.......};

struct

struct FONT_DEF
{
char store_width;
char glyph_height;
const char glyph_table[];
char fixed_width;
const char width_table[];
char glyph_beg;
char glyph_end;
char glyph_def;
};

const struct FONT_DEF fonts[FONT_COUNT] = {
#ifdef EN_FIVE_DOT
{1, 7, test, 0, test_A,' ','~','.'},
#endif

#ifdef EN_SIX_DOT
{2, 8, test_B, 0, test_BB,' ','~','.'},
#endif
}

regards,

gerrit
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Mar 25, 2006 3:16 pm     Reply with quote

First off, what processor are you using?

There are limitations on array sizes in 16F series chips.
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Sat Mar 25, 2006 4:22 pm     Reply with quote

I'm using a 18F6622 micro.

Sorry for not mentioning.

I want to access som const char arrays indirect via a structure.

I need to memcpy or memmove data from some location in the const char array to a normal char array

Or are ther better ways to do this ?

Gerrit
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 25, 2006 7:01 pm     Reply with quote

Data and program space are different in the pics. You would have to use a pointer to a const array in your struct. However, CCS doesn't support pointers to const so that will not work either. You could just use an int value to specify which const array the struct is using and then use a switch statement on the int value to access the const array.
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Sun Mar 26, 2006 3:20 am     Reply with quote

Hello Mark,

I thought it would come to this. Only this solution makes me less flexible
in adding members to the structure.

I will think it over and try to make somethink that fits my needs

Thanks to you for replying.

Gerrit

P.S. will version 4 include * to const !!
Ttelmah
Guest







PostPosted: Sun Mar 26, 2006 7:47 am     Reply with quote

However, it is worth remembering that if the const array, is a simple integer array, you can access this with normal array accesses. This ought (untried...), to allow transfers if needed with a union. So as a example:
Code:

struct demo {
   char str[8];
   int16 word;
   int8  b;
};

union link {
   struct demo sform;
   int8 array[11];
};

const union link cvar = {//Initialise here};

struct demo ram_version;

//You then should be able to move the contents of 'cvar', into
//'ram_version', with:
int8 count;
for (count=0;count<sizeof(struct demo);count++)
   *(((int8 *)&ram_version)+count)=cvar.array[count];

This will need some tidying up, but might be the basis for withdrawing structure blocks from constant declarations, and placing them in RAM as needed.

Best Wishes
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