On May 26, 12:42 am, "JohnQ" <
[email protected]>
wrote:
During A nothing happens, theres no A.
On my systems (Solaris, Linux and Windows), the program is
loaded from disk before starting execution at the entry point.
And static initialization takes place during the load from disk.
Of course, all this isn't very relevant to the C++ programmer.
Static initialization takes place some time before the first
line of code gets executed, or at least before it is possible to
access the variable in any way. So whether the system does it
when loading the program, or arranges for the first access to
trap, and does it then, there's no way to tell in your program.
Imagine main or WinMain on windows being the normal function called by
RealEntryPoint - first function called on executing your program,
in effect it calls your main or WinMain function.
Between call to RealEntryPoint and main function, class static, file
static, function static, global variables are constructed.
Maybe. In practice, this will happen before the first line of
your code in main, but technically, the standard allows a later
initialization.
By standard in random order, but in effect being order of the object
files are linked into the main executable.
An unspecified order. Except that the order is specified within
a single source file; it's only the order of the source files
are treated in which is unspecified. And historically, at least
(i.e. with CFront), the order was in fact the opposite the order
of inclusion by the linker. (As far as I know, this was never
documented nor guaranteed. But it did cover up a certain number
of errors, since statics in low level libraries tended to be
constructed before any statics in the code which used them.) A
quick check shows that g++ still respects this order.