Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Confused about calling constructors using brace syntax.

23 views
Skip to first unread message

Paul

unread,
Jan 12, 2017, 8:54:56 PM1/12/17
to
In the below code, I'm unclear as to what Data result = {} does. Is this
the same as Data result = Data();
After the line Data result = {}; are the values of bytes all equal to 0,
or are they garbage values? I'm thinking garbage values but I'm not sure.
Many thanks for your help.
Paul


struct Data {
char bytes[16];
};

Data f() {
Data result = {};
// generate result
return result;
}

int main() {
Data d = f();
}

Alf P. Steinbach

unread,
Jan 13, 2017, 1:19:19 AM1/13/17
to
On 13.01.2017 02:54, Paul wrote:
> In the below code, I'm unclear as to what Data result = {} does. Is this
> the same as Data result = Data();

Yes, in the sense of having the same effect in this case.


> After the line Data result = {}; are the values of bytes all equal to 0,

Yes.

> or are they garbage values?

No.


> I'm thinking garbage values but I'm not sure.
> Many thanks for your help.
> Paul
>
>
> struct Data {
> char bytes[16];
> };
>
> Data f() {
> Data result = {};
> // generate result
> return result;
> }
>
> int main() {
> Data d = f();
> }
>

Cheers,

- Alf

Paul

unread,
Jan 13, 2017, 6:46:13 AM1/13/17
to
Many thanks,

Paul
0 new messages