VC++ compiler warning C4345

  • Thread starter Thread starter Bit Byte
  • Start date Start date
B

Bit Byte

I have the following warning:

warning C4345: behavior change: an object of POD type constructed with
an initializer of the form () will be default-initialized

Should I care (if yes, why?)
Should I worry (if no, under what conditions should I worry ? - if yes why?)

I looked on the MS site for help with this warning but the examples
giving are pretty scant and info about this (via Google) is generally
scant ...
 
Bit said:
I have the following warning:

warning C4345: behavior change: an object of POD type constructed with
an initializer of the form () will be default-initialized

Should I care (if yes, why?)
Should I worry (if no, under what conditions should I worry ? - if yes why?)

I looked on the MS site for help with this warning but the examples
giving are pretty scant and info about this (via Google) is generally
scant ...

Show us a minimal code snippet that give you this warning....

Arnaud
MVP -VC
 
Bit Byte said:
I have the following warning:

warning C4345: behavior change: an object of POD type constructed
with an initializer of the form () will be default-initialized

Should I care (if yes, why?)

Yes, because this is what the compiler should do.
Should I worry (if no, under what conditions should I worry ? - if
yes why?)

No, it is actually an improvement, as this is required by the
standard. Earlier versions did't do it right, or was produced before
there was a standard.


Bo Persson
 
I have the following warning:

warning C4345: behavior change: an object of POD type constructed with
an initializer of the form () will be default-initialized

Should I care (if yes, why?)

This means it will be zero-initialized, as required by the standard. For
example, the following should cause the created objects to be
zero-initialized:

int* p = new int();

struct X
{
int x;
};

X* q = new X();

However, the following syntax (note the lack of parens) leaves the
variables uninitialized;

int* p = new int;
X* q = new X;
Should I worry (if no, under what conditions should I worry ? - if yes why?)

It sounds like you weren't expecting any particular value (and if you were,
the only one you had any right to expect was zero, in which case, be happy,
because now you'll get it reliably), so zero should be as good as any. The
only downside is that it takes a little extra code to accomplish this.
 
Back
Top