(ref.doc)kanze 080993
Next dshaker 011093
Prev: kim 030993
Up: Usenet
Newsgroups: comp.std.c++ (Note:
Kanze)
|> : unit (or source file). Most compilers implement this by calling
|> : all static constructors before calling main(). However, if one
|> : static constructor referres to another static object, most
|> : implementations break down (I'm not sure if the standard
|> : addresses this, either).
|> This is exactly what is at issue here. Neither "most implementations"
|> nor the ARM address this issue, except that in commentary, the ARM
|> exhorts you to pity the poor compiler and not use *truly* circular cases.
|> But it leaved things quite ambiguoous about cross-module references with
|> static initializers.
This is one point where the ARM (Note:
ARM) is not really ambiguous;
section 3.4: "The initialization of nonlocal static objects in a
translation unit is done before the first use of any functin or object
defined in that translation unit. ... No further order is imposed on
the initialization of objects from different translation units." This
seems to be a clear statement that you cannot count on the order in
any way.
Although not ambiguous, there are two problems with this statement:
1. It cannot be implemented. In particular, if a function or object
defined in one translation unit is used in the constructor of a static
object in another translation unit, it is possible that even this rule
will result in circular dependancies. I believe that the most
widespread interpretation is that "first use" actually means "first
use after the call to 'main'," but I can find no text to support this.
2. It is not sufficient. No one I know is happy with the rule. The
problem here is that until now, no one has proposed a better one.
automatically generated by info2www version 1.2.2.8