4 ms·
Then just make a define with the default values #define FOO_INIT_DEFAULT {.bar=1} I don’t want some 'magic' struct that behaves different than all other s
by pantalaimon 4y ago
Then just make a define with the default values
#define FOO_INIT_DEFAULT {.bar=1}
I don’t want some 'magic' struct that behaves different than all other structs on init.
A static (default zero) struct lives in .bss, that entire section is zeroed on init.
If you want to have default values, it goes to .data where it will consume some ROM.
- flohofwoe 4y agoIf you want your structs to be zero initialized, then you just wouldn't declare default values in the struct declaration, and everything would work as before. Also, once you initialize structs with values somewhere in the code (for instance with designated init), there's a high chance that the compiler will put a copy into the data section anyway, which is then memcpy'ed into the runtime struct (it depends on the compiler and compile options).