Hi all,
I would like to get some guidance in the use of c strings in my firmware.
In the past, I would use String variables, even knowing that in embedded devices this could cause trouble (memory leaks? unsure).
So I understand this is not recommended:
String a = "string not recommended";
Anyhow, these days I’m trying to stay away, but I came across something I’d like to understand.
What is recommended to use with Particle devices, char b[] or char *b?
Example:
char amessage[] = "now is the time"; // <- is this recommended?
char *pmessage = "now is the time"; // <- or is this the way to go?
Reading on the Internet, this is what I got from this StackOverflow answer:
(There’s) a subtle difference. Essentially, the former:
char amessage[] = "now is the time";
Defines an array whose members live in the current scope’s stack space, whereas:
char *pmessage = "now is the time";
Defines a pointer that lives in the current scope’s stack space, but that references memory elsewhere (in this one, “now is the time” is stored elsewhere in memory, commonly a string table).
So my question is: what version is better to use with Particle devices?
Thanks!
Gustavo.