From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 References: <43a5572d-ea50-41a8-9897-9900f13c5a00@www.fastmail.com> In-Reply-To: From: Charles Forsyth Date: Tue, 2 Apr 2019 20:57:29 +0100 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary="000000000000a824110585918c66" Subject: Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Topicbox-Message-UUID: f88e1950-ead9-11e9-9d60-3106f5b1d025 --000000000000a824110585918c66 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable yes, how true. On Tue, 2 Apr 2019 at 18:22, Devon H. O'Dell wrote: > Also worth noting that any padding bits are zeroed as well for > aggregate and union types. Not just setting all pointer values to NULL > and arithmetic types to positive or unsigned zero. > > Op di 2 apr. 2019 om 08:17 schreef Skip Tavakkolian > : > > > > like this: > > > > #include > > #include > > > > struct option { > > int n; > > char *s; > > int flags; > > }; > > > > > > int main(void) > > { > > struct option opt =3D { 1, "test" }; > > static struct option opt2; > > > > printf("%d %s %x\n", opt.n, opt.s, opt.flags); > > printf("%x\n", opt2.flags); > > return 0; > > } > > > > > > On Tue, Apr 2, 2019 at 8:02 AM Skip Tavakkolian < > skip.tavakkolian@gmail.com> wrote: > >> > >> I interpret it as: initialize it like a static variable. > >> > >> On Tue, Apr 2, 2019 at 7:53 AM Kyohei Kadota wrote: > >>> > >>> Thank you for a reply. > >>> > >>> I read spec on > http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf > >>> then I'm confusing. > >>> This spec describes Initialization: > >>> > >>> > 6.7.8 Initialization, p127 > >>> > > >>> > 19 The initialization shall occur in initializer list order, each > initializer provided for a > >>> > particular subobject overriding any previously listed initializer > for the same subobject;132) > >>> > all subobjects that are not initialized explicitly shall be > initialized implicitly the same as > >>> > objects that have static storage duration. > >>> > >>> What is "be initialized implicitly the same as objects that have > >>> static storage duration" mean? > >>> > >>> 2019=E5=B9=B44=E6=9C=882=E6=97=A5(=E7=81=AB) 9:27 Jeremy O'Brien : > >>> > > >>> > On Mon, Apr 1, 2019, at 11:33, Kyohei Kadota wrote: > >>> > > Hi, 9fans. I use 9legacy. > >>> > > > >>> > > About below program, I expected that flags field will initialize = to > >>> > > zero but the value of flags was a garbage, ex, "f8f7". > >>> > > Is this expected? > >>> > > > >>> > > ``` > >>> > > #include > >>> > > > >>> > > struct option { > >>> > > int n; > >>> > > char *s; > >>> > > int flags; > >>> > > }; > >>> > > > >>> > > int > >>> > > main(void) > >>> > > { > >>> > > struct option opt =3D {1, "test"}; > >>> > > printf("%d %s %x\n", opt.n, opt.s, opt.flags); > >>> > > return 0; > >>> > > } > >>> > > ``` > >>> > > > >>> > > > >>> > > >>> > According to C99: "If an object that has automatic storage duration > is not initialized explicitly, its value is indeterminate." > >>> > > >>> > Stack variable =3D=3D automatic storage duration. This appears to b= e > correct behavior to me. > >>> > > >>> > > --000000000000a824110585918c66 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
yes, how true.

On Tue, 2 Apr 2019 at 18:22, Devon H. O'= Dell <devon.odell@gmail.com= > wrote:
Also= worth noting that any padding bits are zeroed as well for
aggregate and union types. Not just setting all pointer values to NULL
and arithmetic types to positive or unsigned zero.

Op di 2 apr. 2019 om 08:17 schreef Skip Tavakkolian
<skip.ta= vakkolian@gmail.com>:
>
> like this:
>
> #include <u.h>
> #include <stdio.h>
>
> struct option {
> int n;
> char *s;
> int flags;
> };
>
>
> int main(void)
> {
> struct option opt =3D { 1, "test" };
> static struct option opt2;
>
> printf("%d %s %x\n", opt.n, opt.s, opt.flags);
> printf("%x\n", opt2.flags);
> return 0;
> }
>
>
> On Tue, Apr 2, 2019 at 8:02 AM Skip Tavakkolian <skip.tavakkolian@gmail.com> wrote:
>>
>> I interpret it as: initialize it like a static variable.
>>
>> On Tue, Apr 2, 2019 at 7:53 AM Kyohei Kadota <
lufia@lufia.org> wrote:
>>>
>>> Thank you for a reply.
>>>
>>> I read spec on http://www.open= -std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
>>> then I'm confusing.
>>> This spec describes Initialization:
>>>
>>> > 6.7.8 Initialization, p127
>>> >
>>> > 19 The initialization shall occur in initializer list ord= er, each initializer provided for a
>>> > particular subobject overriding any previously listed ini= tializer for the same subobject;132)
>>> > all subobjects that are not initialized explicitly shall = be initialized implicitly the same as
>>> > objects that have static storage duration.
>>>
>>> What is "be initialized implicitly the same as objects th= at have
>>> static storage duration" mean?
>>>
>>> 2019=E5=B9=B44=E6=9C=882=E6=97=A5(=E7=81=AB) 9:27 Jeremy O'= ;Brien <neutra= l@fastmail.com>:
>>> >
>>> > On Mon, Apr 1, 2019, at 11:33, Kyohei Kadota wrote:
>>> > > Hi, 9fans. I use 9legacy.
>>> > >
>>> > > About below program, I expected that flags field wil= l initialize to
>>> > > zero but the value of flags was a garbage, ex, "= ;f8f7".
>>> > > Is this expected?
>>> > >
>>> > > ```
>>> > > #include <stdio.h>
>>> > >
>>> > > struct option {
>>> > >=C2=A0 =C2=A0 =C2=A0int n;
>>> > >=C2=A0 =C2=A0 =C2=A0char *s;
>>> > >=C2=A0 =C2=A0 =C2=A0int flags;
>>> > > };
>>> > >
>>> > > int
>>> > > main(void)
>>> > > {
>>> > >=C2=A0 =C2=A0 =C2=A0struct option opt =3D {1, "t= est"};
>>> > >=C2=A0 =C2=A0 =C2=A0printf("%d %s %x\n", op= t.n, opt.s, opt.flags);
>>> > >=C2=A0 =C2=A0 =C2=A0return 0;
>>> > > }
>>> > > ```
>>> > >
>>> > >
>>> >
>>> > According to C99: "If an object that has automatic s= torage duration is not initialized explicitly, its value is indeterminate.&= quot;
>>> >
>>> > Stack variable =3D=3D automatic storage duration. This ap= pears to be correct behavior to me.
>>> >
>>>

--000000000000a824110585918c66--