This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: High priority bug?


Carlo Wood wrote:
> 
> On Wed, Jun 06, 2001 at 01:30:27PM +1200, Ross Smith wrote:
> > relevant) may be initialised either at some point before the call to
> > main() or at some point before their first use in the same translation
> > unit. (See section 3.6.2 of the C++ standard.) No promises are made
> > about the order of initialisation between different translation units.
> 
> Ok, but as I wrote, this *is* in the same translation unit.  Yet there
> is no check here whether or not the object was initialized.
> 
> If what happened is allowed then the following program is not garanteed
> to work - is that true?
> 
> #include <limits>
> 
> int const failure = std::numeric_limits<int>::min();
> 
> struct A {
>   A(void) {
>     // use 'failure', ie:
>     if (failure == 0)
>       raise(3); // core dump
>   }
> };
> 
> A a;
> 
> Note that this DOES work, but it is not garanteed to work, is that what
> you are saying?

Yes. I made a small mistake in my description above. The rule is that
dynamic initialisation is only guaranteed to take place before the
_later_ of (1) the first statement of main() and (2) the first use
(anywhere) of any function or object in the translation unit where the
object in question is defined.

(This is off topic for the list; if you want further elaboration, please
post to comp.lang.c++.moderated or comp.std.c++.)

-- 
Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
========================================================================
        "Hungarian notation is the tactical nuclear weapon of
         source code obfuscation techniques." -- Roedy Green


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]