Question Regarding Static Initialisation of Aggregates.

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

  1. John Smith

    John Smith Guest


    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

    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.

    John Smith, Apr 19, 2006
    1. Advertisements

  2. 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
    1. Advertisements

  3. John Smith

    Flash Gordon Guest

    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.
    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 -
    comp.lang.c posting guidelines and intro:

    Inviato da X-Privat.Org - Registrazione gratuita
    Flash Gordon, Apr 19, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.