Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Does extern "const" allocate storage? Message-ID: <3287@haddock.ISC.COM> Date: 1 Apr 88 19:54:33 GMT References: <7712@apple.Apple.Com> <3034@haddock.ISC.COM> <613@mcrware.UUCP> <3117@haddock.ISC.COM> <3938@chinet.UUCP> <3241@haddock.ISC.COM> <4381@chinet.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 21 In article <4381@chinet.UUCP> dag@chinet.UUCP (Daniel A. Glasser) writes: >---- begin file 1 ----- > const int x = 5; > int foo() { return x; } >---- begin file 2 ----- > extern const int x; > extern int foo(); > int fie() { return x == foo(); } >---- end example ----- >Maybe the compiler is at liberty to substitute the value 5 for the use of x >in the function foo [but it isn't allowed to omit the storage entirely]. I think we're in agreement now. What I claim is that (a) the substitution is valid if the compiler knows the value, and (b) if *all* possible references are so optimized, then the compiler need not allocate the space. This is normally possible only if the object has non-external linkage. Actually, it's theoretically possible even in your example, if the compiler is willing to do cross-file optimization. (It would also have to "know" that no library routines depend on x.) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint