|
|
View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
search string strstr |
Posted: Thu Apr 30, 2020 6:56 am |
|
|
Hello,
I am using strstr to search for specific string and it works OK:
Code: |
unsigned int8 STRCON[]={"0,CONNECT"};
unsigned int8 STRCLO[]={"0,CLOSED"};
unsigned int8 ASKAPS[]={"ASKAPS"};
if(strstr(RxBuf,STRCON)!=0) DoStuff();
else if(strstr(RxBuf,STRCLO)!=0) DoStuff1();
else if(strstr(RxBuf,ASKAPS)!=0) DoStuff2();
|
The above works but if I make the strings const to save RAM I get "Attempt to create a pointer to a constant" Error.
Code: |
const unsigned int8 STRCON[]={"0,CONNECT"};
const unsigned int8 STRCLO[]={"0,CLOSED"};
const unsigned int8 ASKAPS[]={"ASKAPS"};
|
Any ideas? _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Apr 30, 2020 7:03 am |
|
|
Add
#device PASS_STRINGS=IN_RAM
at the top of your code immediately after the line including the
processor definition file.
The 'reason', is because of the architecture of the PIC. It uses a
Harvard architecture, which means the program memory is a completely
separate memory 'space' to the RAM. Pointers are addresses in RAM,
and a const string (in ROM), is not in RAM. Hence a pointer cannot
be constructed to this.
This line adds a little extra code to 'virtualise' accesses to the ROM
so that pointers can be used.
Be aware this only works with compilers for the last few years (V5.). |
|
|
|
|
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
|