Liste des Groupes | Revenir à cl c++ |
On 30.03.2025 18:30, Muttley@DastardlyHQ.org wrote:The literalist reading of that wording fails miserably if a real world program uses a global constructor/initializer to cause some desired imperative effect outside the C++ runtime state. Examples include setting the CPU clock frequency of a small system, outputting some kind of welcome message to the human user etc. etc.On Sun, 30 Mar 2025 10:38:57 -0400"If it [initialization] is deferred, it strongly happens before any
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.
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.
Les messages affichés proviennent d'usenet.