Question Regarding Static Initialisation of Aggregates.

Discussion in 'C Programming' started by John Smith, Apr 19, 2006.

  1. John Smith

    John Smith Guest

    Hi,

    I have a question regarding the initialisation of aggregates:

    The C (99) standard states:
    section 6.7.8, paragraph 21 states:
    If there are fewer initializers in a brace-enclosed list than there are
    elements or members of an aggregate, or fewer characters in a string
    literal used to initialize an array of known size than there are elements
    in the array, the remainder of the aggregate shall be
    initialized implicitly the same as objects that have static storage
    duration.

    Does "remainder" here refer to padding as well or just field types (for
    aggregates)? My experiments with gcc seem to indicate padding is zeroed as
    well but I just want to confirm.

    Thanks
     
    John Smith, Apr 19, 2006
    #1
    1. Advertising

  2. John Smith wrote:
    > Hi,
    >
    > I have a question regarding the initialisation of aggregates:
    >
    > The C (99) standard states:
    > section 6.7.8, paragraph 21 states:
    > If there are fewer initializers in a brace-enclosed list than there are
    > elements or members of an aggregate, or fewer characters in a string
    > literal used to initialize an array of known size than there are elements
    > in the array, the remainder of the aggregate shall be
    > initialized implicitly the same as objects that have static storage
    > duration.
    >
    > Does "remainder" here refer to padding as well or just field types (for
    > aggregates)? My experiments with gcc seem to indicate padding is zeroed as
    > well but I just want to confirm.


    I don't think there's any requirement on initialising padding elements
    at all. I'd asume their value is random. I guess you may rely on
    (hopefully documented) behaviour of a particular compiler, but would
    lose portability in the process.
     
    Vladimir S. Oka, Apr 19, 2006
    #2
    1. Advertising

  3. John Smith

    Flash Gordon Guest

    John Smith wrote:
    > Hi,
    >
    > I have a question regarding the initialisation of aggregates:
    >
    > The C (99) standard states:
    > section 6.7.8, paragraph 21 states:
    > If there are fewer initializers in a brace-enclosed list than there are
    > elements or members of an aggregate, or fewer characters in a string
    > literal used to initialize an array of known size than there are elements
    > in the array, the remainder of the aggregate shall be
    > initialized implicitly the same as objects that have static storage
    > duration.


    The above is talking about members of the aggregate. Padding is space
    between the members, it is not members. So padding may not be
    initialised to 0.

    > Does "remainder" here refer to padding as well or just field types (for
    > aggregates)? My experiments with gcc seem to indicate padding is zeroed as
    > well but I just want to confirm.


    There is no guarantee. It could initialise the padding bytes or leave
    them untouched. gcc is probably initialising them because that was
    either the easy or the efficient way to do it on your platform.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc

    Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
     
    Flash Gordon, Apr 19, 2006
    #3
    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. Kot

    Question - aggregates..

    Kot, Sep 12, 2003, in forum: VHDL
    Replies:
    4
    Views:
    631
  2. Anand P Paralkar

    Using Aggregates in Case Expressions

    Anand P Paralkar, Oct 27, 2003, in forum: VHDL
    Replies:
    6
    Views:
    617
    Anand P Paralkar
    Oct 28, 2003
  3. Gary Thorpe

    Using aggregates for assignments

    Gary Thorpe, Jun 14, 2004, in forum: VHDL
    Replies:
    4
    Views:
    697
  4. Tim Hubberstey

    "Interesting" behavior with aggregates

    Tim Hubberstey, Jun 25, 2004, in forum: VHDL
    Replies:
    6
    Views:
    1,824
    Tim Hubberstey
    Jun 30, 2004
  5. Tim Clacy
    Replies:
    8
    Views:
    394
    Tim Clacy
    May 30, 2006
Loading...

Share This Page