Technically this should be on the C++ language group, but I want an answer, not to either be sneered at or to start a religious war.
I think this works the same if it's C, once you take out the C++-isms.
So, here's an array definition. All is hunky-dory -- I'm specifying four English-language strings for four possible fault conditions. No prob.
const char * const CHealth::_faultStrings[4] = { "no status message", "user fault test", "motor supply over limit", "motor supply under limit" };
Under the gnu compiler, if I leave out one of the commas this construct compiles without a whimper -- it just makes three strings, one of which is longer than you thought. Then later, when you get a motor supply under limit fault, it happily takes an uninitialized pointer and crashes the machine (or not, depending on build details).
Is there a way to write this so that if you specify a too-short array the compiler will automatically complain? Causing an error would be best, but popping a warning would be OK since I've got the thing flagged to error out on warnings.
Knowing some g++ flag to add would work for me for now; having some guaranteed way to make any ANSI-conformant compiler bomb during the build would be better.