static local object initialization

Discussion in 'C++' started by AlexWalk, Jun 23, 2010.

  1. AlexWalk

    AlexWalk Guest

    Hello. The C++ textbooks or articles I've read so far state that
    static local objects are initialized the first time the control flows
    over their declarations. For example, "The C++ Programming Language"
    by Bjarne Stroustrup says so. The C++ FAQ Lite says so. But today I
    accidentally read about the ISO C++ standard, which doesn't says so.
    It says:

    [6.7.4] An implementation is permitted to perform
    early initialization of other local objects with static storage
    duration under the same conditions that an
    implementation is permitted to statically initialize an object with
    static storage duration in namespace scope
    (3.6.2). Otherwise such an object is initialized the first time
    control passes through its declaration; ...

    Does this mean the statements in those C++ textbooks are incorrect?
    Does this mean depending on the "intialization-on-first-entry"
    behavior will have some unexpected result?
     
    AlexWalk, Jun 23, 2010
    #1
    1. Advertising

  2. * AlexWalk, on 23.06.2010 06:00:
    > Hello. The C++ textbooks or articles I've read so far state that
    > static local objects are initialized the first time the control flows
    > over their declarations. For example, "The C++ Programming Language"
    > by Bjarne Stroustrup says so. The C++ FAQ Lite says so. But today I
    > accidentally read about the ISO C++ standard, which doesn't says so.
    > It says:
    >
    > [6.7.4] An implementation is permitted to perform
    > early initialization of other local objects with static storage
    > duration under the same conditions that an
    > implementation is permitted to statically initialize an object with
    > static storage duration in namespace scope
    > (3.6.2). Otherwise such an object is initialized the first time
    > control passes through its declaration; ...
    >
    > Does this mean the statements in those C++ textbooks are incorrect?


    No, it's just an "as if" optimization, hence the reference to conditions.


    > Does this mean depending on the "intialization-on-first-entry"
    > behavior will have some unexpected result?


    No.


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
     
    Alf P. Steinbach /Usenet, Jun 23, 2010
    #2
    1. Advertising

  3. AlexWalk

    AlexWalk Guest

    On 6ÔÂ23ÈÕ, ÏÂÎç12ʱ05·Ö, "Alf P. Steinbach /Usenet" <alf.p.steinbach
    > wrote:
    > * AlexWalk, on 23.06.2010 06:00:
    >
    >
    >
    >
    >
    > > Hello. The C++ textbooks or articles I've read so far state that
    > > static local objects are initialized the first time the control flows
    > > over their declarations. For example, "The C++ Programming Language"
    > > by Bjarne Stroustrup says so. The C++ FAQ Lite says so. But today I
    > > accidentally read about the ISO C++ standard, which doesn't says so.
    > > It says:

    >
    > > [6.7.4] An implementation is permitted to perform
    > > early initialization of other local objects with static storage
    > > duration under the same conditions that an
    > > implementation is permitted to statically initialize an object with
    > > static storage duration in namespace scope
    > > (3.6.2). Otherwise such an object is initialized the first time
    > > control passes through its declaration; ...

    >
    > > Does this mean the statements in those C++ textbooks are incorrect?

    >
    > No, it's just an "as if" optimization, hence the reference to conditions.


    Oh, I see the difference. The standard says "statically initialize".
    Thanks for your reply.

    > > Does this mean depending on the "intialization-on-first-entry"
    > > behavior will have some unexpected result?

    >
    > No.
    >
    > Cheers & hth.,
    >
    > - Alf
    >
    > --
    > blog at <url:http://alfps.wordpress.com>
     
    AlexWalk, Jun 23, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Hoffmann
    Replies:
    3
    Views:
    2,845
    Christian Janßen
    Aug 8, 2003
  2. Ali
    Replies:
    4
    Views:
    912
  3. , India
    Replies:
    1
    Views:
    331
    , India
    Apr 21, 2008
  4. auspicious
    Replies:
    0
    Views:
    327
    auspicious
    Sep 25, 2008
  5. Brian Cole
    Replies:
    16
    Views:
    871
    James Kanze
    Dec 8, 2008
Loading...

Share This Page