开发者

Value initialize aggregate

Tried C++ standard, but c开发者_C百科ouldn't figure it out. Are these equivalent?

double x[2] = {0.0, 0.0};

and

double x[2] = {};

How about these?

struct A {
    double x[2];
};

A a = {0.0, 0.0};

and

A a = {};

Thank you!


The C++ standard says (8.5.1):

If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized

and value-initialization of a double is to set it to 0.0.

So yes! In C++ they are equivalent.

[I haven't had time to check the C99 standard.]


Yes, they are.

Compiler fills the initialization with zeroes when not enough given per declared size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜