Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!bloom-beacon!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: forward declaration of array; how? Keywords: ANSI, forward, static, array Message-ID: <14868@haddock.ima.isc.com> Date: 11 Oct 89 17:26:44 GMT References: <2364@munnari.oz.au> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 19 In article <2364@munnari.oz.au> ok@cs.mu.oz.au (Richard O'Keefe) writes: > extern void (*(dispatch[]))(); > static void (*(dispatch[]))() = { ... foo, ..., baz, ... }; The ANSI way to do this is to use `static' rather than `extern' in the first declaration. This makes it a `tentative definition', which can be thought of as a kludge around the ambiguity between declarations and uninitialized definitions; it retroactively becomes a definition only if no real definition appears before the end of the translation unit. In this case, the initialized declaration later on would be the real definition, causing the earlier one to be treated as a forward declaration only. Unfortunately, not all existing pre-ANSI compilers agree with this. Even more unfortunately, some do not have *any* way to forward-declare a static object, so you can't just use `#if __STDC__ static #else extern #endif' and expect it to be portable. For full portability (without rearranging it to be a backward reference), you'd need to make the `dispatch' object global instead of static. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint