4

If with C++17 I do a

struct tm mytm{};
int i{};

Will the variable mytm (and to be on the safe side, also i) be zero-initialized?

I am sent in circles through these pages:

And the closest thing I can find is from zero-initialization:

..., including value initialization of elements of aggregates for which no initializers are provided

The alternative (I somehow feel right about) would be default-initialization, which would mean no-initialization. But I find this too, value-initialization, meaning zeros. Confused...

(I note, that by the C struct-initialization the initializer can not be empty. So the argument "like in C" does not hold here.)

cigien
  • 57,834
  • 11
  • 73
  • 112
towi
  • 21,587
  • 28
  • 106
  • 187
  • What is a "C struct"? – Nicol Bolas May 13 '20 at 18:03
  • @NicolBolas I called a C struct something that would work in C, like "struct tm" from my question. This from the C++ point of view would be a struct with no private data members and no virtual functions. You closed the question with a reference *how* to initialize something to 0, namely with `{0}`, which was not my question. The answer you gave there -- so you say `struct tm mytm{}` is value-initialization. Right? Which in this case... is zero-initialized by "when a named variable (automatic...) is declared with the initializer consisting of a pair of braces." Correct? – towi May 14 '20 at 10:07
  • "*which was not my question.*" It was for all useful purposes. It would be answered by any answer to that question (ie: you can't in general, even for your "C structs", and your question still lacks a firm definition for this concept). – Nicol Bolas May 14 '20 at 13:23

0 Answers0