View previous topic :: View next topic |
Author |
Message |
heliodoro.alegre
Joined: 20 Nov 2013 Posts: 6
|
flash string management |
Posted: Wed Nov 20, 2013 5:35 am |
|
|
I have an old project compiled with C version 3.249
for PIC18F6722 with the code:
Code: |
const char Strings1[5][17] =
{" string number 1 ",
" string number 2 ",
" string number 3 ",
" string number 4 ",
" string number 4 "};
int II;
II = 2;
printf (Strings1[II]);
|
worked correctly.
I have try to compile with C version 4.114 for
PIC18F67K22 and I have an error in printf
"Attempt to create a pointer to a constant"
Can anybody help me. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 20, 2013 1:14 pm |
|
|
Post a small complete test program that shows the problem. And fix
the problems in your posted code. The strings in your two dimensional
array actually have 19 characters in them, including the spaces at the
beginning and the end. Also, there is a string-terminator byte of 0x00.
So the actual declared row length should be 20, not 17. Also, you
have two strings called "string number 4".
Fix all that and make a test program that I can work with, and maybe
I can solve your problem.
This thread has some sample test programs. Note the general style.
They are very short and complete. The only have code necessary to
show the problem. There is no Wizard code or code to disable timers, etc.
Post a test program for your problem that is similar in overall style:
http://www.ccsinfo.com/forum/viewtopic.php?t=25483 |
|
![](templates/subSilver/images/spacer.gif) |
heliodoro.alegre
Joined: 20 Nov 2013 Posts: 6
|
|
Posted: Thu Nov 21, 2013 5:50 am |
|
|
The problem is con string length. In real code is correct
Code: |
const char Strings1[5][17] =
{" string num 1 ",
" string num 2 ",
" string num 3 ",
" string num 4 ",
" string num 5 "};
int II;
II = 2;
printf (Strings1[II]); |
Code in link you have sent has constant indexes
Code: | glcd_putc(info[1]);
glcd_putc(info[2]); |
With constant indexes there is no problem.
The compile error appears when index is a variable.
I have a way to solve the problem, define
Code: | char RamString[100]; |
and change printf
Code: | strcpy (Strings1[II], RamString);
printf (RamString);
|
But it is a long work because there is a lot of similar
printf in code.
The question is, C version 3.249 accept my original code
and version 4.114 not.
Can I make 4.114 compatible with this code anyway with
a # pre procesor directive or a command line parameter? |
|
![](templates/subSilver/images/spacer.gif) |
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Thu Nov 21, 2013 6:11 am |
|
|
#device PASS_STRINGS=IN_RAM |
|
![](templates/subSilver/images/spacer.gif) |
heliodoro.alegre
Joined: 20 Nov 2013 Posts: 6
|
|
Posted: Tue Nov 26, 2013 3:11 am |
|
|
This #define
#device PASS_STRINGS=IN_RAM
has not the effects I desired, error persists.
I will go on with the copy in ram method
strcpy (Strings1[II], RamString);
printf (RamString);
In this way I know exctly what compiler is doing.
Thanks you for your interest. |
|
![](templates/subSilver/images/spacer.gif) |
|