Timeline for #define VS local static const char
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 5, 2017 at 7:14 | comment | added | Manitoba | Thanks @Andrew for the clear explanation, I really got it. | |
| May 4, 2017 at 8:06 | history | edited | Andrew | CC BY-SA 3.0 |
added 13 characters in body
|
| May 4, 2017 at 8:06 | comment | added | Andrew | As Michel indicated in his answer the F() macro will store the string in flash and not copy it to RAM which will use less memory but may give a tiny performance hit. | |
| May 4, 2017 at 8:03 | comment | added | Andrew | A static variable declared within a function is basically a global variable that the compiler won't let other parts of the code access. It exists at all times, not just when the function is called and so takes a constant amount of memory. If it was local but not static then it would only use RAM when in the function but you would have the performance hit of copying the string from flash to RAM every time the function was called. | |
| May 3, 2017 at 15:49 | comment | added | Manitoba |
Thanks for this detailed reply. So does this also apply to static const char arrays declared only locally (and therefore only called when the function itself is called?
|
|
| May 3, 2017 at 15:44 | vote | accept | Manitoba | ||
| May 3, 2017 at 14:50 | history | answered | Andrew | CC BY-SA 3.0 |