Uninitialized externals and statics

David Brooks dbrooks at osf.osf.org
Sat Aug 26 14:38:37 AEST 1989


In article <1989Aug25.185428.3511 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
[...]
> There is one, repeat one, special
>case:  an integer constant expression of value zero -- repeat, an
>integer CONSTANT expression of value ZERO -- gets turned into a NULL
>pointer of the appropriate type when compared to a pointer.  Note that
>it is the integer, not the pointer, that is converted.  Note that no
>such conversion is done on integer variables, integer constant expressions
>with non-zero values, or general integer expressions.

I was about to make the same point myself.  This can be determined by
careful reading of K&R II: try section A6.6, page 198.  The constant 0
may be converted by a cast, by assignment, or by comparison, to a
pointer.  This legitimizes "if (p == 0)".  Requiring an actual
conversion step removes any implicatino that the pointer is zero-valued.

Anyway, I had a question: what is this assumption about "all bits
zero" for the common case of initializing ints?  I wonder if there's
any machine out there that represents int 0 with some other bit
pattern...

Those of us old enough to remember when ones-complement seemed like a
good idea can begin to break into a sweat at this point :-)
-- 
David Brooks			dbrooks at osf.org
Open Software Foundation	uunet!osf.org!dbrooks
11 Cambridge Center		Personal views, not necessarily those
Cambridge, MA 02142, USA	of OSF, its sponsors or members.



More information about the Comp.lang.c mailing list