9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Skip Tavakkolian <skip.tavakkolian@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Don't Plan 9 C compiler initialize the rest of member of a struct?
Date: Tue,  2 Apr 2019 08:14:50 -0700	[thread overview]
Message-ID: <CAJSxfmLYzz+YJFsP=T8r6VzEGxKeVi9H+328Srp99YLdsoxLpg@mail.gmail.com> (raw)
In-Reply-To: <CAJSxfmJLkebcNB87mYMfJ4bV7WWBHNUBA_pgpsfTLq8KyvV2vA@mail.gmail.com>

[-- 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 --]

  reply	other threads:[~2019-04-02 15:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 15:32 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJSxfmLYzz+YJFsP=T8r6VzEGxKeVi9H+328Srp99YLdsoxLpg@mail.gmail.com' \
    --to=skip.tavakkolian@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).