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

Info on PASS_STRINGS=IN_RAM

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



Joined: 20 May 2016
Posts: 10

View user's profile Send private message

Info on PASS_STRINGS=IN_RAM
PostPosted: Sat Mar 18, 2017 3:43 am     Reply with quote

Hi All,
I need some help to understand: PASS_STRINGS=IN_RAM.
What real happen?

Code:
 
PASS_STRINGS=IN_RAM
#define str "Hello"

void main ()
{
while(1){
printf(str);
}}

The str is copied in ram when the Pic is programmed or is copied every time I call printf?

I hope the second one, right?. Manual:
A new way to pass constant strings
to a function by first copying the
string to RAM and then passing a
pointer to RAM to the function.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Sat Mar 18, 2017 4:45 am     Reply with quote

It's basically copied when you use it. However internally it's slightly more complex. The 'buffer' used is much smaller than the longest string you use. So you can have:

Code:

const string1[] = "One test string";
const string2[] = "Another test string";


Then pass these to functions expecting 'char *', as if they are in RAM.

The buffer used is only a few bytes, but there is an added overhead, in that the compiler has to add code to 'know' how to handle this.
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