Lifetime of pointers value

tuxduino:
You mean the entire string is copied on the stack ? Interesting...

What would come out of the compiler if local_string[] was declared const ?

Going to check out...

The correct way to tell the compiler not to treat the string (or any local variable) as something which will persist only while the function has not yet returned to its caller is to use the static keyword:

static char local_string[] = "this string will be stored (and will survive) just like a global variable, but it will only be scoped as a local variable (so you can only reference it while in the function)"

will achieve what you want here.

A dirty (but useful) trick would also be to use a P() macro to get a pointer to the string program flash; I don't think whatever happens the stack's ever gonna touch it there! :wink:

In embedded programming, sometimes you win clean, and sometimes you win dirty. But the important thing is to win. (Some of the cleverest tricks I've seen in embedded programming have also been the filthiest.)