Topic: Static objects construct before main, right?
Author: hcobb@slip.net
Date: 1995/05/25 Raw View
The C++ FAQs book, question number 180: (WRT file scope static
objects)"...Their constructors are invoked before main() begins
executing..."
I used to believe this, and had a system where entire modules where
simply presented to the linker and bound in with the program (by having
a FSSO register itself with a singleton.)
But I reread the ARM and noticed that the actual rule was "...is done
before the first use of any function or object defined in that
translation unit" (ARM: 3.4)
This makes considerable sense, if you consider a program that only drags
a great deal of DLL objects in on rare executions. (Otherwise you pay
the startup cost of every "module" that might be invoked, at the start
of each run)
--
Henry J. Cobb hcobb@slip.net ftp://ftp.cdrom.com/pub/misc/sfb
All items Copyright (c) 1995, by their respective authors, permission is
granted to redistribute as long as proper credit is given.