Re: Initialization of unnamed "subobjects"

Discussion in 'C Programming' started by Ben Bacarisse, Jun 13, 2010.

  1. William Ahern <william@wilbur.25thandClement.com> writes:

    > Is C99 6.7.8p9


    You mean p19. I was *really* confused until I saw the 19 later on!

    > just a catch-all which actually catches nothing for struct
    > objects? Or am I confused about the definition of subobject. Take, for
    > example,
    >
    > struct { int a, int b; } x = { .b = 3 };
    >
    > Is .a a subobject within the meaning of p19, or are "subobjects" only
    > members of members?


    No, I think we have one object (x) with two subobjects (x.a and x.b).
    x.b is explicitly initialised and x.a is implicitly initialised as if x
    had been an object of static storage duration (i.e. to 0).

    > For example, with
    >
    > struct { int a; struct { int c, d; } b; } x = { .b = { .c = 1 } };
    >
    > are the only "subobjects" here .c and .d, so that .d is implicitly
    > initialized but .a is not?


    I think the subobjects are x.a, x.b, x.b.d and x.b.d. I am pretty sure
    that the intent is that x.a and x.b.d are both implicitly initialised.
    Is there some wording that leads you to think that "subobject" has a
    meaning more subtle than an object that is part of a larger one?

    --
    Ben.
     
    Ben Bacarisse, Jun 13, 2010
    #1
    1. Advertising

  2. On Sat, 12 Jun 2010 19:52:44 -0700, William Ahern
    <william@wilbur.25thandClement.com> wrote:

    >Ben Bacarisse <> wrote:
    >> William Ahern <william@wilbur.25thandClement.com> writes:

    >
    >> > Is C99 6.7.8p9

    >
    >> You mean p19. I was *really* confused until I saw the 19 later on!

    >
    >No, p9--"[e]xcept where explicitly stated otherwise, for the purposes of
    >this subclause unnamed members of objects of structure [type]... do not
    >participate in initialization." However, according to p19 all unnamed
    >members _are_ initialized. So, what's the point of p9, at least regarding
    >structure types?


    P19 does not contain the word "unnamed". Therefore, it cannot be one
    of the "explicitly stated otherwise" clauses referred to in p9.

    On the other had, since there is no way to referenced an unnamed
    subobject, how would you ever know?

    >
    >I figured that either p9 is effectively vestigal in this context, or there
    >was an important distinction intended by the use of "members", "objects", or
    >"subobjects".
    >
    >The reason I'm analyzing this is that I submitted a patch to LLVM to silence
    >warnings when re-initializing subobjects (extremely annoying as I do this in
    >a considerable amount of code), and I wanted to make sure I wasn't missing
    >something.


    What is the benefit of providing multiple initialization for the same
    object when all but the last will be ignored? Doesn't it just confuse
    people trying to read the code since you do it often?

    --
    Remove del for email
     
    Barry Schwarz, Jun 13, 2010
    #2
    1. Advertising

  3. William Ahern <william@wilbur.25thandClement.com> writes:

    > Ben Bacarisse <> wrote:
    >> William Ahern <william@wilbur.25thandClement.com> writes:

    >
    >> > Is C99 6.7.8p9

    >
    >> You mean p19. I was *really* confused until I saw the 19 later on!

    >
    > No, p9--"[e]xcept where explicitly stated otherwise, for the purposes of
    > this subclause unnamed members of objects of structure [type]... do not
    > participate in initialization." However, according to p19 all unnamed
    > members _are_ initialized. So, what's the point of p9, at least regarding
    > structure types?


    So you were talking about the interaction between p9 and p19? In that
    case what was confusing (to me) was that your examples did not include
    any unnamed objects in the sense of p9.

    > I figured that either p9 is effectively vestigal in this context, or there
    > was an important distinction intended by the use of "members", "objects", or
    > "subobjects".


    p9 seems to me to be about struct members that have no name. I think
    this is only possible with bit-fields but maybe the language is general
    "just in case".

    p9 and p19 do interact in the following sense: does the wording of p19
    concerning "subobjects that are not initialized explicitly" count as
    "explicitly stated otherwise" in p9. I.e. in this case:

    struct s { int : 16; int x : 16; } s = { .x = 42 };

    does p9 rule and the unnamed field is indeterminate or does p19 rule and
    it gets zero-initialised?

    > The reason I'm analyzing this is that I submitted a patch to LLVM to silence
    > warnings when re-initializing subobjects (extremely annoying as I do this in
    > a considerable amount of code), and I wanted to make sure I wasn't missing
    > something.


    I don't see what p9 has to do with that situation. This opinion is
    based in what an unnamed member of a structure is -- I think you have
    taken it to be about missing designated initialisers, but that does not
    seem to make sense. For one thing, C89 has similar (though simpler)
    wording on this matter it does not have "named" initialisers.

    <snip>
    --
    Ben.
     
    Ben Bacarisse, Jun 13, 2010
    #3
  4. Ben Bacarisse

    Tim Rentsch Guest

    William Ahern <william@wilbur.25thandClement.com> writes:

    > Ben Bacarisse <> wrote:
    >> William Ahern <william@wilbur.25thandClement.com> writes:

    >
    >> > Is C99 6.7.8p9

    >
    >> You mean p19. I was *really* confused until I saw the 19 later on!

    >
    > No, p9--"[e]xcept where explicitly stated otherwise, for the purposes of
    > this subclause unnamed members of objects of structure [type]... do not
    > participate in initialization." However, according to p19 all unnamed
    > members _are_ initialized. So, what's the point of p9, at least regarding
    > structure types?


    The phrasing is unfortunately a bit cryptic. Saying unnamed members
    "do not participate" means that those members don't count for
    taking up an element expression in an (anonymous) initializer list.

    (And of course 'unnamed members' means bit-fields with no associated
    identifier, but that came out later in the thread.)
     
    Tim Rentsch, Jun 20, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mattia Belletti

    unnamed object creation

    Mattia Belletti, Oct 20, 2003, in forum: Java
    Replies:
    4
    Views:
    435
    Jason Us
    Oct 22, 2003
  2. Mysooru

    Unnamed "Formal Parameter"

    Mysooru, Jul 24, 2003, in forum: C++
    Replies:
    3
    Views:
    461
    Mike Wahler
    Jul 24, 2003
  3. Razmig K
    Replies:
    3
    Views:
    700
    John L Fjellstad
    Sep 5, 2003
  4. Jordi Vilar
    Replies:
    5
    Views:
    2,292
    Jonathan Turkanis
    Feb 18, 2004
  5. Andr?
    Replies:
    1
    Views:
    106
Loading...

Share This Page