View previous topic :: View next topic |
Author |
Message |
wlpuah
Joined: 30 Jan 2009 Posts: 2
|
Problem access array of constant strings |
Posted: Fri Jan 30, 2009 3:45 am |
|
|
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
|
|
Posted: Fri Jan 30, 2009 9:40 am |
|
|
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
|
|
Posted: Fri Jan 30, 2009 8:35 pm |
|
|
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
|
|
Posted: Fri Jan 30, 2009 11:08 pm |
|
|
Finally find the solution for above problem.
Use strcpy to copy the data in program memory to RAM.
Thanks all. |
|
|
|