Liste des Groupes | Revenir à cl c++ |
On Sun, 30 Mar 2025 15:30:34 +0000, Muttley wrote:
>On Sun, 30 Mar 2025 10:38:57 -0400 James Kuyper>
<jameskuyper@alumni.caltech.edu> wibbled:On 3/30/25 4:57 AM, Muttley@DastardlyHQ.org wrote:I was curious about the order in which objects get constructed in>
modules before main gets called. It seems with both Clang and gcc its
the order in which the modules were linked together to form the
runnable binary so if the link order was m1.o m2.o then anything in m1
would get constructed first.Vice verca if you switch the order.>
Is this codified in the standard or is it left up to compiler and
linker writers to decide how they order this?
Section 6.9.3.3 does in fact impose many constraints on the sequence in
which non-local objects with static storage duration get initialized.
However, all of the sequence requirements are only between objects
defined in the same translation unit. Also, it's implementation-defined
which of those initializations occur before the start of main().
Initialising global objects before main is an absolute must otherwise
how are you expected to use them safely? They're not in the code for
decoration.
Global variables are really bad, you are wrong to think it is OK to use
them.
Les messages affichés proviennent d'usenet.