10 ms·
There's also a way to do this without any user-defined functions that works in both C and C++: struct tm tm_struct = { 0, };
by dezgeg 12y ago
There's also a way to do this without any user-defined functions that works in both C and C++:
struct tm tm_struct = { 0, };
- cremno 12y agoIn ISO C++ and GNU C you can also omit the 0: struct tm tm_struct = { };
- JoeAltmaier 12y agoDoes that work on char array members in the struct?
- readerrrr 12y agoIn C, using: struct tm tm_struct = { 0 } ;, the rest of the struct including padding is initialized to zero bits.
- dezgeg 12y agoYes, as far as I believe, this should always work in standard C89/C99. In the char array case, it works due to the brace elision rule in aggregates: assuming struct foo { char bar[3]; }; These declarations are equivalent: struct foo f1 = { 0, }; struct foo f2 = { { 0, } };