struct inheritance need?

Sergey Gromov snake.scaly at gmail.com
Mon Dec 22 03:14:41 PST 2008


Sun, 21 Dec 2008 12:04:42 -0500, Kagamin wrote:

> Sergey Gromov Wrote:
> 
>> C++ static object constructors execute at run time except for trivial
>> cases.
> 
> Although I think it's not guaranteed to work this way and compiler
> decides when to execute constructor. So code should be ready for
> run-time evaluation. And as code evolves those constructors can
> switch back and forth between ct and rt evaluation. 
> 
> ps I know a C++ programmer, he wanted to control manually, in what
> order static object constructors are called :)

Actually, static constructors are *guaranteed* to run at run time,
before main().  Compiler *may* optimize them out and convert into
initialized DATA if there are no side effects, that is, if optimized
program works exactly as if all static ctors were executed at run time.

C++ guarantees that static ctors are executed in order they appear in a
module.  There is no guarantee about the order in which different
modules are initialized though.


More information about the Digitalmars-d-learn mailing list