Re: Don't Plan 9 C compiler initialize the rest of member of a struct?

Kyohei Kadota <[email protected]>
Newsgroups gmane.os.plan9.general
Message-ID <CAFMepckUx1aMg48iw=eBXiVkxg_BvnbjqQqT9OVLTdhd=eSxaQ@mail.gmail.com>
I see, I understand. thank you, Skip, Charles.

2019年4月3日(水) 0:06 Charles Forsyth <[email protected]>:
>
>
>> What is "be initialized implicitly the same as objects that have
>> static storage duration" mean?
>
>
> It refers back to the second part of case 10 of that section.
>
> On Tue, 2 Apr 2019 at 15:53, Kyohei Kadota <[email protected]> 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年4月2日(火) 9:27 Jeremy O'Brien <[email protected]>:
>> >
>> > 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 <stdio.h>
>> > >
>> > > struct option {
>> > >     int n;
>> > >     char *s;
>> > >     int flags;
>> > > };
>> > >
>> > > int
>> > > main(void)
>> > > {
>> > >     struct option opt = {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 == automatic storage duration. This appears to be correct behavior to me.
>> >
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.