Topic: The demise of C+@ and Jim Fleming (was C+@ Standard Class Library)
Author: mikem@bga.com (Mike Maddux)
Date: 1995/05/30 Raw View
In article <3q74dh$bnq@punchdown.zocalo.com>,
Kalyan Kolachala <kal@chromatic.com> wrote:
>
>I think there is a confusion between objects declared static
>(i.e file scope) and objects of static storage duration.
>By "static" the draft refers to the latter.
"static" seems to be an excessively overloaded keyword in C and C++.
Mike Maddux
Author: dent@highway1.com.au (Andy Dent)
Date: 1995/05/25 Raw View
In article <3q18ms$cs6@hamlet.ot.com.au>,
jamesb@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (James Brister)
wrote:
>When that happens I will feel the same sort
>of emptyness one feels after driving by a traffic accident--not pretty
>and you sort of want to go back and look again, but you know you're
>better off going on.
chuckle
>
>Ob C++:
>Is it guaranteed that a static object's constructors will be called
>before main() starts, or only before it's accessed?
What's the difference, from a user view? Are you embedding some
side-effects in the constructor?
ARM p92 says "Init of a local object with storage class statis is done the
first time control passes through its declaration." I'm not sure what this
means for a file-scope static object. I have a vague memory of an example
showing this occurring before main() but in an indeterminate order
(amongst the .cpp files). I just tried to find the reference in the c++
FAQ and Coplien but couldn't.
BTW I couldn't reply to this guy directly - James, you should take your
own advice!
Andy Dent, Product Architect, A.D. Software, Western Australia
OOFILE - "the cross-platform OODBMS that speaks c++"
ftp://ftp.highway1.com.au/pub/adsoftware/oofile/
http://www.highway1.com.au/adsoftware/oofile.html
Author: mikem@bga.com (Mike Maddux)
Date: 1995/05/25 Raw View
In article <3q18ms$cs6@hamlet.ot.com.au>,
James Brister <jamesb@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN> wrote:
>
>Ob C++:
>Is it guaranteed that a static object's constructors will be called
>before main() starts, or only before it's accessed?
>
I think that the constructor of a static object is guaranteed to be
called before main() starts.
Mike Maddux
Author: jamesb@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (James Brister)
Date: 1995/05/25 Raw View
Mike Maddux (mikem@bga.com) wrote:
[ about Jim Fleming ]
: He did not
: answer that and he has never, in the several months I have been following
: his threads with a strange morbid fascination, answered that question or any
: similar question.
I predict that JF will eventually give up and get back on his boat (or
maybe will be seen wandering around Times Square mumbling to himself
about the big conspiracy). When that happens I will feel the same sort
of emptyness one feels after driving by a traffic accident--not pretty
and you sort of want to go back and look again, but you know you're
better off going on.
Ob C++:
Is it guaranteed that a static object's constructors will be called
before main() starts, or only before it's accessed?
James
Author: matt@dogbert.lbl.gov (Matthew Austern)
Date: 1995/05/25 Raw View
In article <dent-2505952315070001@adsoftware.highway1.com.au> dent@highway1.com.au (Andy Dent) writes:
> ARM p92 says "Init of a local object with storage class statis is done the
> first time control passes through its declaration." I'm not sure what this
> means for a file-scope static object. I have a vague memory of an example
> showing this occurring before main() but in an indeterminate order
> (amongst the .cpp files). I just tried to find the reference in the c++
> FAQ and Coplien but couldn't.
It is guaranteed that static objects defined in a compilation unit
will be constructed before the first call to any function defined in
that compilation unit. It is not guaranteed that this will occur
before execution of main().
Occasionally it's necessary to have better control of construction
order; the standard example is the construction of cout and cin.
There are a few tricks you can use to do that.
--
Matt Austern matt@physics.berkeley.edu
http://dogbert.lbl.gov/~matt
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1995/05/26 Raw View
Matthew Austern (matt@dogbert.lbl.gov) wrote:
|> In article <dent-2505952315070001@adsoftware.highway1.com.au> dent@highway1.com.au (Andy Dent) writes:
|> > ARM p92 says "Init of a local object with storage class statis is done the
|> > first time control passes through its declaration." I'm not sure what this
|> > means for a file-scope static object. I have a vague memory of an example
|> > showing this occurring before main() but in an indeterminate order
|> > (amongst the .cpp files). I just tried to find the reference in the c++
|> > FAQ and Coplien but couldn't.
|> It is guaranteed that static objects defined in a compilation unit
|> will be constructed before the first call to any function defined in
|> that compilation unit. It is not guaranteed that this will occur
|> before execution of main().
Actually, you're not even guaranteed that much, despite what it says in
the draft. The best I've seen is that it will be constructed before the
first call to any function defined in the compilation unit *and* called
directly or indirectly from main.
Calling a function in the compilation unit from the constructor of
another static object may still result in the function being called
before the static object is constructed. (A little thought will show
that since cyclic dependencies are possible otherwise, this restriction
must be present, whether the standard allows it or not.)
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
--Beratung in industrieller Datenverarbeitung
Author: Kalyan Kolachala <kal@chromatic.com>
Date: 1995/05/27 Raw View
kanze@gabi-soft.fr (J. Kanze) wrote:
>Matthew Austern (matt@dogbert.lbl.gov) wrote:
>|> In article
<dent-2505952315070001@adsoftware.highway1.com.au>
dent@highway1.com.au (Andy Dent) writes:
>
>|> > ARM p92 says "Init of a local object with storage class
statis is done the
>|> > first time control passes through its declaration." I'm
not sure what this
>|> > means for a file-scope static object. I have a vague
memory of an example
>|> > showing this occurring before main() but in an
indeterminate order
>|> > (amongst the .cpp files). I just tried to find the
reference in the c++
>|> > FAQ and Coplien but couldn't.
>
>|> It is guaranteed that static objects defined in a
compilation unit
>|> will be constructed before the first call to any function
defined in
>|> that compilation unit. It is not guaranteed that this will
occur
>|> before execution of main().
>
I think there is a confusion between objects declared static
(i.e file scope) and objects of static storage duration.
By "static" the draft refers to the latter.
My understanding of the draft is that default initialization
to 0 is guaranteed for all statics before their use but nothing
can be guaranteed if the initialization involves a constructor
call. In such cases the language only promises that objects
will be initialized in the order they are declared in a
translation unit (basically a "file"). This property is used
by the nifty counter scheme etc to initialize statics before
their use though this technique doesn't work for cyclic
dependencies.
But to me the case of cyclic dependencies seems to be more of a
theoretical issue than anything else and I couldn't think of a
realistic case of such an occurence, which cannot be obviated.
Any ideas?
- Kalyan