nectar at celabo
Sep 15, 2002, 7:00 AM
Post #1 of 1
On Sun, Sep 15, 2002 at 03:05:32AM -0700, silvio [at] big wrote:
C initialization of static objects (was: ALERT ALERT ALERT! google under attack ALERT ALERT ALERT!)
> now.. this is true for _unix_ (static will be in bss which is required to
> be zero'd). but not in terms of C directly, which states that its simply
> undefined if not initialized.
> there's alot of this style of unix coding about in software.. which makes the
> assumption that since its global or static, then it'll be zero.
Programmers make this assumption because it is a true assumption :-)
_The C Programming Language_, 2nd edition says it most clearly on
p219: ``A static object not explicitly initialized is initialized as
if it (or its members) were assigned the constant 0.''
ISO/IEC 9899:1999 (C99) is a bit more verbose (section 6.7.8
paragraph 10): ``If an object that has static storage duration is
not initialized explicitly, then: if it has pointer type, it is
initialized to a null pointer; if it has arithmetic type, it is
initialized to (positive or unsigned) zero; if it is an aggregate,
every member is initialized (recursively) according to these rules;
if it is a union, the first named member is initialized (recursively)
according to these rules. ''
> must suck to port :)
Yes, it does, but not for this reason.
Jacques A. Vidrine <nectar [at] celabo> http://www.celabo.org/
NTT/Verio SME . FreeBSD UNIX . Heimdal Kerberos
jvidrine [at] verio . nectar [at] FreeBSD . nectar [at] kth