* [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? @ 2019-04-01 15:32 Kyohei Kadota 2019-04-01 23:49 ` Skip Tavakkolian 2019-04-02 0:26 ` Jeremy O'Brien 0 siblings, 2 replies; 20+ messages in thread From: Kyohei Kadota @ 2019-04-01 15:32 UTC (permalink / raw) To: 9fans 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; } ``` ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-01 15:32 [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota @ 2019-04-01 23:49 ` Skip Tavakkolian 2019-04-02 14:44 ` Kyohei Kadota 2019-04-02 0:26 ` Jeremy O'Brien 1 sibling, 1 reply; 20+ messages in thread From: Skip Tavakkolian @ 2019-04-01 23:49 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 627 bytes --] 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 <lufia@lufia.org> 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; > } > ``` > > [-- Attachment #2: Type: text/html, Size: 1026 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-01 23:49 ` Skip Tavakkolian @ 2019-04-02 14:44 ` Kyohei Kadota 0 siblings, 0 replies; 20+ messages in thread From: Kyohei Kadota @ 2019-04-02 14:44 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs I ran this code on 386 machine on QEMU based public VPC service. 2019年4月2日(火) 9:27 Skip Tavakkolian <skip.tavakkolian@gmail.com>: > > 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 <lufia@lufia.org> 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; >> } >> ``` >> ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-01 15:32 [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2019-04-01 23:49 ` Skip Tavakkolian @ 2019-04-02 0:26 ` Jeremy O'Brien 2019-04-02 0:35 ` Charles Forsyth ` (2 more replies) 1 sibling, 3 replies; 20+ messages in thread From: Jeremy O'Brien @ 2019-04-02 0:26 UTC (permalink / raw) To: 9fans 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. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 0:26 ` Jeremy O'Brien @ 2019-04-02 0:35 ` Charles Forsyth 2019-04-02 0:35 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? Kurt H Maier 2019-04-02 14:52 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2 siblings, 0 replies; 20+ messages in thread From: Charles Forsyth @ 2019-04-02 0:35 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 1108 bytes --] 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 <neutral@fastmail.com> 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 <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. > > [-- Attachment #2: Type: text/html, Size: 1589 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 0:26 ` Jeremy O'Brien 2019-04-02 0:35 ` Charles Forsyth @ 2019-04-02 0:35 ` Kurt H Maier 2019-04-02 1:20 ` Dan Cross 2019-04-02 14:52 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2 siblings, 1 reply; 20+ messages in thread From: Kurt H Maier @ 2019-04-02 0:35 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs 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 <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. > Can anyone provide the patches 9legacy uses to implement C99 compliance? Thanks in advance, khm ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 0:35 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? Kurt H Maier @ 2019-04-02 1:20 ` Dan Cross 2019-04-02 2:22 ` Kurt H Maier 0 siblings, 1 reply; 20+ messages in thread From: Dan Cross @ 2019-04-02 1:20 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 2282 bytes --] On Mon, Apr 1, 2019 at 8:36 PM Kurt H Maier <khm@sciops.net> 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 <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. > > > > 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. [-- Attachment #2: Type: text/html, Size: 2957 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 1:20 ` Dan Cross @ 2019-04-02 2:22 ` Kurt H Maier 2019-04-02 3:06 ` Skip Tavakkolian 2019-04-02 10:38 ` Charles Forsyth 0 siblings, 2 replies; 20+ messages in thread From: Kurt H Maier @ 2019-04-02 2:22 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs 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 <khm@sciops.net> 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 <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. > > > > > > > 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 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 2:22 ` Kurt H Maier @ 2019-04-02 3:06 ` Skip Tavakkolian 2019-04-02 8:02 ` David du Colombier 2019-04-02 10:38 ` Charles Forsyth 1 sibling, 1 reply; 20+ messages in thread From: Skip Tavakkolian @ 2019-04-02 3:06 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 2781 bytes --] 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 <khm@sciops.net> 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 <khm@sciops.net> 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 <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. > > > > > > > > > > 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 > > [-- Attachment #2: Type: text/html, Size: 3803 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 3:06 ` Skip Tavakkolian @ 2019-04-02 8:02 ` David du Colombier 0 siblings, 0 replies; 20+ messages in thread From: David du Colombier @ 2019-04-02 8:02 UTC (permalink / raw) To: 9fans 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 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 2:22 ` Kurt H Maier 2019-04-02 3:06 ` Skip Tavakkolian @ 2019-04-02 10:38 ` Charles Forsyth 2019-04-02 16:25 ` Anthony Martin 1 sibling, 1 reply; 20+ messages in thread From: Charles Forsyth @ 2019-04-02 10:38 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 3564 bytes --] > > 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 <khm@sciops.net> 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 <khm@sciops.net> 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 <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. > > > > > > > > > > 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 > > [-- Attachment #2: Type: text/html, Size: 4741 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 10:38 ` Charles Forsyth @ 2019-04-02 16:25 ` Anthony Martin 2019-04-02 16:37 ` Charles Forsyth 0 siblings, 1 reply; 20+ messages in thread From: Anthony Martin @ 2019-04-02 16:25 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs Charles Forsyth <charles.forsyth@gmail.com> 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 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? 2019-04-02 16:25 ` Anthony Martin @ 2019-04-02 16:37 ` Charles Forsyth 0 siblings, 0 replies; 20+ messages in thread From: Charles Forsyth @ 2019-04-02 16:37 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 614 bytes --] covered and covered1 On Tue, 2 Apr 2019 at 17:26, Anthony Martin <ality@pbrane.org> wrote: > Charles Forsyth <charles.forsyth@gmail.com> 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 > > [-- Attachment #2: Type: text/html, Size: 1017 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 0:26 ` Jeremy O'Brien 2019-04-02 0:35 ` Charles Forsyth 2019-04-02 0:35 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? Kurt H Maier @ 2019-04-02 14:52 ` Kyohei Kadota 2019-04-02 15:02 ` Skip Tavakkolian 2019-04-02 15:04 ` Charles Forsyth 2 siblings, 2 replies; 20+ messages in thread From: Kyohei Kadota @ 2019-04-02 14:52 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs 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 <neutral@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 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. > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 14:52 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota @ 2019-04-02 15:02 ` Skip Tavakkolian 2019-04-02 15:14 ` Skip Tavakkolian 2019-04-02 15:04 ` Charles Forsyth 1 sibling, 1 reply; 20+ messages in thread From: Skip Tavakkolian @ 2019-04-02 15:02 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 1734 bytes --] 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 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 <neutral@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 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. > > > > [-- Attachment #2: Type: text/html, Size: 2543 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 15:02 ` Skip Tavakkolian @ 2019-04-02 15:14 ` Skip Tavakkolian 2019-04-02 16:18 ` Devon H. O'Dell 0 siblings, 1 reply; 20+ messages in thread From: Skip Tavakkolian @ 2019-04-02 15:14 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 2171 bytes --] like this: #include <u.h> #include <stdio.h> 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.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 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 <neutral@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 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. >> > >> >> [-- Attachment #2: Type: text/html, Size: 3817 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 15:14 ` Skip Tavakkolian @ 2019-04-02 16:18 ` Devon H. O'Dell 2019-04-02 19:57 ` Charles Forsyth 0 siblings, 1 reply; 20+ messages in thread From: Devon H. O'Dell @ 2019-04-02 16:18 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs 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.tavakkolian@gmail.com>: > > like this: > > #include <u.h> > #include <stdio.h> > > 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.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 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 <neutral@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 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. >>> > >>> ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 16:18 ` Devon H. O'Dell @ 2019-04-02 19:57 ` Charles Forsyth 0 siblings, 0 replies; 20+ messages in thread From: Charles Forsyth @ 2019-04-02 19:57 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 2817 bytes --] 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.tavakkolian@gmail.com>: > > > > like this: > > > > #include <u.h> > > #include <stdio.h> > > > > 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.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 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 <neutral@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 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. > >>> > > >>> > > [-- Attachment #2: Type: text/html, Size: 4488 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 14:52 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2019-04-02 15:02 ` Skip Tavakkolian @ 2019-04-02 15:04 ` Charles Forsyth 2019-04-02 15:16 ` Kyohei Kadota 1 sibling, 1 reply; 20+ messages in thread From: Charles Forsyth @ 2019-04-02 15:04 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs [-- Attachment #1: Type: text/plain, Size: 1843 bytes --] > 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 <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 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 <neutral@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 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. > > > > [-- Attachment #2: Type: text/html, Size: 2910 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? 2019-04-02 15:04 ` Charles Forsyth @ 2019-04-02 15:16 ` Kyohei Kadota 0 siblings, 0 replies; 20+ messages in thread From: Kyohei Kadota @ 2019-04-02 15:16 UTC (permalink / raw) To: Fans of the OS Plan 9 from Bell Labs I see, I understand. thank you, Skip, Charles. 2019年4月3日(水) 0:06 Charles Forsyth <charles.forsyth@gmail.com>: > > >> 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 <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 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 <neutral@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 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. >> > >> ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2019-04-02 19:57 UTC | newest] Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-04-01 15:32 [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2019-04-01 23:49 ` Skip Tavakkolian 2019-04-02 14:44 ` Kyohei Kadota 2019-04-02 0:26 ` Jeremy O'Brien 2019-04-02 0:35 ` Charles Forsyth 2019-04-02 0:35 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a?struct? Kurt H Maier 2019-04-02 1:20 ` Dan Cross 2019-04-02 2:22 ` Kurt H Maier 2019-04-02 3:06 ` Skip Tavakkolian 2019-04-02 8:02 ` David du Colombier 2019-04-02 10:38 ` Charles Forsyth 2019-04-02 16:25 ` Anthony Martin 2019-04-02 16:37 ` Charles Forsyth 2019-04-02 14:52 ` [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct? Kyohei Kadota 2019-04-02 15:02 ` Skip Tavakkolian 2019-04-02 15:14 ` Skip Tavakkolian 2019-04-02 16:18 ` Devon H. O'Dell 2019-04-02 19:57 ` Charles Forsyth 2019-04-02 15:04 ` Charles Forsyth 2019-04-02 15:16 ` Kyohei Kadota
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).