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 CCS Technical Support

Problem access array of constant strings

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



Joined: 30 Jan 2009
Posts: 2

View user's profile Send private message

Problem access array of constant strings
PostPosted: Fri Jan 30, 2009 3:45 am     Reply with quote

compiler PCH 4.039 MCU PIC18F66J60

I have a problem to access array of constant strings.

Array of constant strings:
Code:

const char *STRING[] =
{
"STRING1",
"STRING2",

"STRINGn"
}

I want to access the string through index to the string like STRING[n].
I cannot compare or access this string correctly. How to access this type of const string?
Ttelmah
Guest







PostPosted: Fri Jan 30, 2009 9:40 am     Reply with quote

Try searching the forum, or reading the manual!......

You could try declaring this using ROM, insteqad of 'const'. However your compiler version is 'borderline', for whether this will work.

Basically, 'const' strings by default, are built to only access as arrays, rather than using pointers. They comprise a table built into the program memory space, together with a program to access this table. Since this is not part of the actual RAM memory space, a RAM pointer won't access them. The ROM declaration, stores a separate table to allow a pointer to be constructed. Has an overhead, but on latter compiler works. Alternatively you can access them using the ANSI declaration, but then they are copied to RAM, and have the space overhead this implies.

Best Wishes
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 30, 2009 8:35 pm     Reply with quote

The CCS C compiler uses a funny way for declaring a const array of strings:

Code:

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


Also, add the following line to the main header file:
#device PASS_STRINGS=IN_RAM

good luck
Noam
_________________
Every solution has a problem.
wlpuah



Joined: 30 Jan 2009
Posts: 2

View user's profile Send private message

PostPosted: Fri Jan 30, 2009 11:08 pm     Reply with quote

Finally find the solution for above problem.
Use strcpy to copy the data in program memory to RAM.
Thanks all.
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