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

constant array of variable length strings

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







constant array of variable length strings
PostPosted: Thu Apr 24, 2008 2:34 am     Reply with quote

keep getting compiler error:
require to be constant:
when I use the following:
char const variable_strings[2] [*] = {"string 1", "string 222"};

Wont recognise [*] ?

Would appreciate if anyone has had the same error. Tks
Ttelmah
Guest







PostPosted: Thu Apr 24, 2008 2:43 am     Reply with quote

What is your compiler version?.
This only started working reasonably well in about the mid 4.030 compilers.

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Thu Apr 24, 2008 4:26 am     Reply with quote

Ttelmah wrote:
What is your compiler version?.
This only started working reasonably well in about the mid 4.030 compilers...

Are you sure about that? This syntax does not even make sense to me. What I have seen is this:
Code:

char const *variable_strings[2] = {"string 1", "string 222"};

where variable_strings is an array of pointers pointing to the various strings. What is the compiler supposed to do with [2][*] ? Does it search through the specified strings and find the longest one and pad them all out with zeroes to make them equal length so indexing arithmetic will work?

Robert Scott
Real-Time Specialties
Ttelmah
Guest







PostPosted: Thu Apr 24, 2008 5:04 am     Reply with quote

The CCS compiler added the ability to have an array of constant text strings that vary in length, without all the wasted storage locations, to pad the strings to a fixed length. The syntax is as shown in the original posting. What happens, is that the data is stored as one long sequence of data (with just NULL characters between), and a separate 'table' is generated, holding the start addresses of each string in this sequence. It _costs_ storage space, if you are only using a couple of strings as shown, and is slower to access, but does work.
If you use the 'search' facility in the manual, for 'const', the last article entitled 'Using Program memory for data', shows the syntax.
The most likely thing to stop the shown syntax working, is that the compiler is set to use ANSI mode, or an older CCS mode. This feature _only_ works if you are running in CCS4 mode (the default), and is disabled in these other modes.

Best Wishes
johnrportsmouth
Guest







pointers to string arrays
PostPosted: Fri Apr 25, 2008 11:46 am     Reply with quote

Thanks for your help and assistance.

yes I have been using the following:

char const *string_array [] = {"string 1", "string 222"};
j = 2;

z = strlen(*string_array[j]);

fprintf (z);

//z does not hold the length of the string
//my problem is I don't quite understand pointers and how to handle them.

Regards
John
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 2:00 am     Reply with quote

Arrays have a zero based index so j=2 will not work.

Try j=0 or j=1
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