By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,203 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,203 IT Pros & Developers. It's quick & easy.

Question Regarding Static Initialisation of Aggregates.

P: n/a
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
Apr 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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.

Apr 19 '06 #2

P: n/a
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
Apr 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.