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

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!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: Mon, 31 Mar 2025 10:29:39 -0400
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <vse8sj$f9o2$1@dont-email.me>
References: <vsb12i$2mv42$1@dont-email.me> <vsbl21$1jsvi$1@dont-email.me>
 <vsbo2p$1p5ov$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 31 Mar 2025 16:29:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="aa3ad9eacc0d58911611c4bd23407394";
	logging-data="501506"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19NE5stpOmo3sSjhTLypC0utyAqcJrxnFE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:BLfJ1teAaOpQC/XzfRHH/r4AZ4Q=
In-Reply-To: <vsbo2p$1p5ov$1@dont-email.me>
Content-Language: en-US
Bytes: 2272

On 30.03.2025 18:30, Muttley@DastardlyHQ.org wrote:
> On Sun, 30 Mar 2025 10:38:57 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wibbled:
>> 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.

"If it [initialization] is deferred, it strongly happens before any
non-initialization odr-use of any non-inline function or non-inline
variable defined in the same translation unit as the variable to be
initialized.47 It is implementation-defined in which threads and at
which points in the program such deferred dynamic initialization
occurs." (6.9.3.3p5).

Therefore, what you need to do is make sure that the object has been
initialized is to access it from a function defined in the same
translation unit.