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

search string strstr

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



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

search string strstr
PostPosted: Thu Apr 30, 2020 6:56 am     Reply with quote

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: 19217

View user's profile Send private message

PostPosted: Thu Apr 30, 2020 7:03 am     Reply with quote

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.).
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