Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Path: utzoo!watmath!clyde!burl!ulysses!allegra!oliveb!Glacier!decwrl!sun!guy
From: guy@sun.uucp (Guy Harris)
Newsgroups: net.lang.c
Subject: Re: Global ptrs init to NULL or 0000?
Message-ID: <2985@sun.uucp>
Date: Sun, 10-Nov-85 18:44:47 EST
Article-I.D.: sun.2985
Posted: Sun Nov 10 18:44:47 1985
Date-Received: Wed, 13-Nov-85 08:25:23 EST
References: <772@whuxl.UUCP> <139200016@uiucdcsb>
Organization: Sun Microsystems, Inc.
Lines: 46

> OK, so what does
> 
> static union {
> 	int i;
> 	char *p;
> 	} foo;
> 
> get initialized to on a machine with a non-0 NULL?

To be pendantic, NULL is a #define and doesn't depend on the machine; you
mean "a machine where null pointers do not contain the same bit pattern as a
0 integral value."

On machines with pre-ANSI C compilers, it doesn't get initialized;

	8.6 Initialization

	...It is not permitted to initialize unions or automatic
	aggregates.

On machines with ANSI C compilers, it gets initialized to whatever bit
pattern a 0 integral value has, since initializing a union initializes only
its first member.  (Yes, this is a rule with limited practical use, but they
had to choose *some* rule, I guess.)

> Incidentally, something like this appears in a LOT of UN*X programs, and
> is a MAJOR headache in attempting to port to a machine with a non-0 NULL.

Which is a good reason why the language specification should have been
silent on the initial value of *any* variable not explicitly initialized.
If you were forced to initialize items with an explicit initialization,
there would be no question about whether a pointer value (even on machines
with non-zero null pointers) which wasn't declared with an initializer would
contain a null pointer or not; it might, but you could NOT count on it.
Furthermore, the question of "what would a union be initialized to" would
not exist either.

Furthermore, non-UNIX environments may have to go through some contortions
to deal with

	int	big_array[32767];

if they don't have UNIX-style automatic zeroing of a BSS area - they might
actually have to put 32767 "int"s worth of zeroes into the executable image.

	Guy Harris