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

2019-04-02 Thread Charles Forsyth
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 = { 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.tavakkol...@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年4月2日(火) 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 = {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.
> >>> >
> >>>
>
>


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

2019-04-02 Thread Charles Forsyth
covered and covered1

On Tue, 2 Apr 2019 at 17:26, Anthony Martin  wrote:

> Charles Forsyth  once said:
> > I didn't look at the code closely enough earlier, but remembered
> something
> > from years ago this morning. It's a bug. It isn't platform specific.
> > There is an existing fix in 9front (I think it came from there) but it's
> > horrible. Still, better a horrible fix than buggy code, so I'll apply it
> to
> > the 9legacy version as well.
>
> It's in /sys/src/cmd/cc/dcl.c:/^contig
>
> What was horrible about the fix?
>
>   Anthony
>
>


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

2019-04-02 Thread Anthony Martin
Charles Forsyth  once said:
> I didn't look at the code closely enough earlier, but remembered something
> from years ago this morning. It's a bug. It isn't platform specific.
> There is an existing fix in 9front (I think it came from there) but it's
> horrible. Still, better a horrible fix than buggy code, so I'll apply it to
> the 9legacy version as well.

It's in /sys/src/cmd/cc/dcl.c:/^contig

What was horrible about the fix? 

  Anthony



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

2019-04-02 Thread Devon H. O'Dell
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 = { 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  
> 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年4月2日(火) 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 = {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.
>>> >
>>>



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

2019-04-02 Thread Kyohei Kadota
I see, I understand. thank you, Skip, Charles.

2019年4月3日(水) 0:06 Charles Forsyth :
>
>
>> 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  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 :
>> >
>> > 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 = {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.
>> >
>>



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

2019-04-02 Thread Skip Tavakkolian
like this:

#include 
#include 

struct option {
int n;
char *s;
int flags;
};


int main(void)
{
struct option opt = { 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 
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年4月2日(火) 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 = {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.
>> >
>>
>>


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

2019-04-02 Thread Charles Forsyth
> 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  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 :
> >
> > 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 = {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.
> >
>
>


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

2019-04-02 Thread Skip Tavakkolian
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年4月2日(火) 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 = {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.
> >
>
>


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

2019-04-02 Thread Kyohei Kadota
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 :
>
> 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 = {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.
>



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

2019-04-02 Thread Kyohei Kadota
I ran this code on 386 machine on QEMU based public VPC service.

2019年4月2日(火) 9:27 Skip Tavakkolian :
>
> It should initialize to zero. 8c and 5c both do the right thing here.
>
> Which distribution and cputype?
>
> On Mon, Apr 1, 2019, 8:34 AM 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 = {1, "test"};
>> printf("%d %s %x\n", opt.n, opt.s, opt.flags);
>> return 0;
>> }
>> ```
>>



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

2019-04-02 Thread Charles Forsyth
>
> In the present case, this appears to be a compiler bug. The aforementioned
> reference to n1548 sec 6.7.9 para 10 is incorrect in that there _is_ an
> explicit initializer here. The relevant text in the standard is sec 6.7.9
> pp 16-21, which specifies that in the event that an explicit initializer
> does not completely cover (in a topological sense) the thing it is
> initializing, then the elements not covered shall be initialized as if they
> had _static_ storage duration; that is, they should be zeroed.


I didn't look at the code closely enough earlier, but remembered something
from years ago this morning. It's a bug. It isn't platform specific.
There is an existing fix in 9front (I think it came from there) but it's
horrible. Still, better a horrible fix than buggy code, so I'll apply it to
the 9legacy version as well.

On Tue, 2 Apr 2019 at 03:23, Kurt H Maier  wrote:

> On Mon, Apr 01, 2019 at 09:20:43PM -0400, Dan Cross wrote:
> > On Mon, Apr 1, 2019 at 8:36 PM Kurt H Maier  wrote:
> >
> > > On Mon, Apr 01, 2019 at 08:26:30PM -0400, Jeremy O'Brien wrote:
> > > > 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 = {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.
> > > >
> > >
> > > Can anyone provide the patches 9legacy uses to implement C99
> compliance?
> >
> >
> > There were actually quite a few of them, mostly done by Geoff Collyer.
> The
> > compiler sources list contains a list of desiderata in a file called
> `c99`;
> > of course, the plan9 compilers aren't completely compliant (they weren't
> > trying to be). Incidentally this file has been carried forward into, for
> > example, /sys/src/cmd/cc/c99 in the 9front distribution (and other plan9
> > derivatives).
> >
> > In the present case, this appears to be a compiler bug. The
> aforementioned
> > reference to n1548 sec 6.7.9 para 10 is incorrect in that there _is_ an
> > explicit initializer here. The relevant text in the standard is sec 6.7.9
> > pp 16-21, which specifies that in the event that an explicit initializer
> > does not completely cover (in a topological sense) the thing it is
> > initializing, then the elements not covered shall be initialized as if
> they
> > had _static_ storage duration; that is, they should be zeroed.
> >
> > Now as I said, the Plan 9 C compilers aren't explicit C99 compliant. But
> > given that the `c99` file describes things related to initializer lists
> as
> > being unneeded because they were already implemented, one may assume it
> was
> > believed that this was covered by c99 behavior. It isn't.
> >
> > - Dan C.
>
> So, no?
>
> khm
>
>


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

2019-04-02 Thread David du Colombier
All the 9legacy patches are available on http://9legacy.org/patch.html.

Most of the compiler changes consist in keeping them in sync
with Charles' updates, available on 
https://bitbucket.org/plan9-from-bell-labs/plan9.

The (partial) C99 changes were done long ago, in March 2006 and before.

https://github.com/0intro/plan9/commits/master/sys/src/cmd/cc

-- 
David du Colombier



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

2019-04-01 Thread Skip Tavakkolian
what I have in /sys/src/cmd/cc here is identical to what's on 9p.io.

On Mon, Apr 1, 2019 at 7:23 PM Kurt H Maier  wrote:

> On Mon, Apr 01, 2019 at 09:20:43PM -0400, Dan Cross wrote:
> > On Mon, Apr 1, 2019 at 8:36 PM Kurt H Maier  wrote:
> >
> > > On Mon, Apr 01, 2019 at 08:26:30PM -0400, Jeremy O'Brien wrote:
> > > > 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 = {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.
> > > >
> > >
> > > Can anyone provide the patches 9legacy uses to implement C99
> compliance?
> >
> >
> > There were actually quite a few of them, mostly done by Geoff Collyer.
> The
> > compiler sources list contains a list of desiderata in a file called
> `c99`;
> > of course, the plan9 compilers aren't completely compliant (they weren't
> > trying to be). Incidentally this file has been carried forward into, for
> > example, /sys/src/cmd/cc/c99 in the 9front distribution (and other plan9
> > derivatives).
> >
> > In the present case, this appears to be a compiler bug. The
> aforementioned
> > reference to n1548 sec 6.7.9 para 10 is incorrect in that there _is_ an
> > explicit initializer here. The relevant text in the standard is sec 6.7.9
> > pp 16-21, which specifies that in the event that an explicit initializer
> > does not completely cover (in a topological sense) the thing it is
> > initializing, then the elements not covered shall be initialized as if
> they
> > had _static_ storage duration; that is, they should be zeroed.
> >
> > Now as I said, the Plan 9 C compilers aren't explicit C99 compliant. But
> > given that the `c99` file describes things related to initializer lists
> as
> > being unneeded because they were already implemented, one may assume it
> was
> > believed that this was covered by c99 behavior. It isn't.
> >
> > - Dan C.
>
> So, no?
>
> khm
>
>


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

2019-04-01 Thread Kurt H Maier
On Mon, Apr 01, 2019 at 09:20:43PM -0400, Dan Cross wrote:
> On Mon, Apr 1, 2019 at 8:36 PM Kurt H Maier  wrote:
> 
> > On Mon, Apr 01, 2019 at 08:26:30PM -0400, Jeremy O'Brien wrote:
> > > 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 = {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.
> > >
> >
> > Can anyone provide the patches 9legacy uses to implement C99 compliance?
> 
> 
> There were actually quite a few of them, mostly done by Geoff Collyer.  The
> compiler sources list contains a list of desiderata in a file called `c99`;
> of course, the plan9 compilers aren't completely compliant (they weren't
> trying to be). Incidentally this file has been carried forward into, for
> example, /sys/src/cmd/cc/c99 in the 9front distribution (and other plan9
> derivatives).
> 
> In the present case, this appears to be a compiler bug. The aforementioned
> reference to n1548 sec 6.7.9 para 10 is incorrect in that there _is_ an
> explicit initializer here. The relevant text in the standard is sec 6.7.9
> pp 16-21, which specifies that in the event that an explicit initializer
> does not completely cover (in a topological sense) the thing it is
> initializing, then the elements not covered shall be initialized as if they
> had _static_ storage duration; that is, they should be zeroed.
> 
> Now as I said, the Plan 9 C compilers aren't explicit C99 compliant. But
> given that the `c99` file describes things related to initializer lists as
> being unneeded because they were already implemented, one may assume it was
> believed that this was covered by c99 behavior. It isn't.
> 
> - Dan C.

So, no?

khm



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

2019-04-01 Thread Dan Cross
On Mon, Apr 1, 2019 at 8:36 PM Kurt H Maier  wrote:

> On Mon, Apr 01, 2019 at 08:26:30PM -0400, Jeremy O'Brien wrote:
> > 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 = {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.
> >
>
> Can anyone provide the patches 9legacy uses to implement C99 compliance?


There were actually quite a few of them, mostly done by Geoff Collyer.  The
compiler sources list contains a list of desiderata in a file called `c99`;
of course, the plan9 compilers aren't completely compliant (they weren't
trying to be). Incidentally this file has been carried forward into, for
example, /sys/src/cmd/cc/c99 in the 9front distribution (and other plan9
derivatives).

In the present case, this appears to be a compiler bug. The aforementioned
reference to n1548 sec 6.7.9 para 10 is incorrect in that there _is_ an
explicit initializer here. The relevant text in the standard is sec 6.7.9
pp 16-21, which specifies that in the event that an explicit initializer
does not completely cover (in a topological sense) the thing it is
initializing, then the elements not covered shall be initialized as if they
had _static_ storage duration; that is, they should be zeroed.

Now as I said, the Plan 9 C compilers aren't explicit C99 compliant. But
given that the `c99` file describes things related to initializer lists as
being unneeded because they were already implemented, one may assume it was
believed that this was covered by c99 behavior. It isn't.

- Dan C.


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

2019-04-01 Thread Charles Forsyth
Yes, that's normal C behaviour. Only external and static storage is
guaranteed to be zero. In a modern environment it seems a little mean,
especially since you gave opt a partial initial value, but there are no
half-measures in C.

On Tue, 2 Apr 2019 at 01:27, Jeremy O'Brien  wrote:

> 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 = {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.
>
>


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

2019-04-01 Thread Kurt H Maier
On Mon, Apr 01, 2019 at 08:26:30PM -0400, Jeremy O'Brien wrote:
> 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 = {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.
> 

Can anyone provide the patches 9legacy uses to implement C99 compliance?


Thanks in advance,
khm



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

2019-04-01 Thread 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 = {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.



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

2019-04-01 Thread Skip Tavakkolian
It should initialize to zero. 8c and 5c both do the right thing here.

Which distribution and cputype?

On Mon, Apr 1, 2019, 8:34 AM 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 = {1, "test"};
> printf("%d %s %x\n", opt.n, opt.s, opt.flags);
> return 0;
> }
> ```
>
>


[9fans] Don't Plan 9 C compiler initialize the rest of member of a struct?

2019-04-01 Thread Kyohei Kadota
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 = {1, "test"};
printf("%d %s %x\n", opt.n, opt.s, opt.flags);
return 0;
}
```