jejones@mcrware.UUCP (James Jones) (03/19/91)
Does p.82, lines 13-15, imply that the following is not standard conforming,
or does p.84, lines 31-34, provide an escape hatch?
James Jones
--------------------begin code fragment
static int i; /* tentative definition, internal linkage */
int
woof(void)
{
return ++i; /* usage other than in sizeof() */
}
--------------------end code fragment
bhoughto@hopi.intel.com (Blair P. Houghton) (03/19/91)
Didn't this just go around? Or is this the "Now let me get this straight" version of the question? In article <5450@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes: >Does p.82, lines 13-15, imply that the following is not standard conforming, >or does p.84, lines 31-34, provide an escape hatch? "No" to the first; and, "it works but it's not escaping from anything" to the second. When the citation on p. 84 says "the behavior is exactly as if the translation unit contains a file scope declaration...with an initializer equal to 0", the imaginary declaration-with-initializer satisfies the requirement from the citation on p. 82, for there to be "exactly one" external definition. I.e., though the explicit external definition is absent, it still properly reserves and initializes storage, which appears to be the intent (the rationale is mute on this). It gets away with this by hiding any definitions for `i' with external linkage from other translation units. I think the sentence on p. 84 could've done with a footnote. vvvvvvvvvvvvv---could be "translation unit" >--------------------begin code fragment >static int i; /* tentative definition, internal linkage */ > >int >woof(void) >{ > return ++i; /* usage other than in sizeof() */ >} >--------------------end code fragment Due to the implicit initial zero, woof() should return 1 the first time it's called, 2 the second, 3 the third, and so on, when compiled by a conforming implementation. --Blair "At least, that's how I read it. Your parsimony may vary."
diamond@jit345.swstokyo.dec.com (Norman Diamond) (03/19/91)
In article <5450@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes: >Does p.82, lines 13-15, imply that the following is not standard conforming, >or does p.84, lines 31-34, provide an escape hatch? > >static int i; /* tentative definition, internal linkage */ >int woof(void) { > return ++i; /* usage other than in sizeof() */ >} Page 84, lines 31-34, appear to be designed exactly for this purpose. -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.
gwyn@smoke.brl.mil (Doug Gwyn) (03/19/91)
In article <5450@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes: >Does p.82, lines 13-15, imply that the following is not standard conforming, >or does p.84, lines 31-34, provide an escape hatch? I don't understand your question -- it's not an "escape hatch", it's an essential specification that says the declaration in your example really is a definition.