Deutsch   English   Français   Italiano  
<vsbl21$1jsvi$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c++
Subject: Re: Pre-main construction order in modules
Date: Sun, 30 Mar 2025 10:38:57 -0400
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <vsbl21$1jsvi$1@dont-email.me>
References: <vsb12i$2mv42$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 30 Mar 2025 16:38:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2b79c0c943797b60432bf1e9021c6a92";
	logging-data="1700850"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19E0SjPY2+XmZQ2VW64JdDiUaQVyhclMHQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YAB4fHduzQN1NhnsuUuqgeh6vPM=
In-Reply-To: <vsb12i$2mv42$1@dont-email.me>
Content-Language: en-US

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().