Calling Global Constructors: Difference between revisions

m
"stored in a stored array" to "stored in a sorted array"
[unchecked revision][unchecked revision]
(Add gcc documentation on initialization to external links)
m ("stored in a stored array" to "stored in a sorted array")
Line 1:
This tutorial discusses how to correctly invoke global constructors, such as those on global C++ objects. These are supposed to have run before your main function, which is why the program entry point is normally a function called _start. This function has the responsibility of parsing the command line arguments, initializing the standard library (memory allocation, signals, ...), running the global constructors and finally exit(main(argc, argv)). Things may be different on your operating system if you change your compiler, but if you are using the GNU Compiler Collection (gcc) it may be wise to follow the System V ABI.
 
On most platforms, the global constructors/destructors are stored in a storedsorted array of function pointers and invoking these is as simple as traversing the array and running each element. However, the compiler does not always give access to this list, and some compilers consider this implementation details. In this case you will have to cooperate with the compiler - fighting the compiler will only cause trouble.
 
== GNU Compiler Collection - System V ABI ==
Anonymous user