I've seen C++ Zero-out a struct array? and other SO posts. Unfortunately I haven't found anything that can initialize a char array member of a struct.
I have this struct
struct SettingsData {
ModeType Mode = ModeType::Off;
char Zone[26];
double Temperature = 0.0;
OnOffState Heater = OnOffState::Off;
OnOffState Airconditioner = OnOffState::Off;
OnOffState Fan = OnOffState::Off;
bool ApplianceOn = false;
};
I'm looking for C++ way of doing this. I realize I should use a member initializer lists but I can't figure out how to initialize the char array. I get
array used as initializer
error.
I've even tried
char Zone[26] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
No compile error, but I'm still seeing unwanted "data" in the Zone member.
char Zone[26] = {0};works for me, so doeschar Zone[26] = {};but I feel like the 0 is more descriptive. Can you elaborate what unwanted data you're seeing right after you instantiate the struct?char Zone[26] = ...doesn't work for C struct members and it doesn't work for C++ struct members either. So... what are you actually trying to do? Is the code in the question the real code? And what does this have to do with embedded systems???