Topic: Availability of a useful feature


Author: jbuck@synopsys.com (Joe Buck)
Date: Wed, 15 Dec 1993 02:40:22 GMT
Raw View
I added comp.std.c++ to the newsgroups list.

hilfinger@CS.Berkeley.EDU writes:
>Here's a somewhat puckish question:

Puckish indeed.

>Can anyone tell me of implementations of C++ that conform to the
>following paragraph from the reference manual (i.e., _The C++
>Programming Language_, 2nd edition)?
>
> "The initialization of non-local static objects (r.3.5) in a
>     translation unit is done before the first use of any function
>  or object defined in that translation unit."
>   Section r.3.4, pg. 485.

No implementation does, since the constraint is impossible to satisfy.
Consider the following files.  Which is initialized first, fooObj or
barObj?  According to the rules, fooObj must be initialized before barObj,
and also vice versa.

file headers.H:
---------------
class Bar;

class Foo {
public:
 static int foo_static_method();
 Foo() : i(Bar::bar_static_method()) {}
private:
 int i;
};

class Bar {
public:
 static int bar_static_method();
 Bar() : i(Foo::foo_static_method()) {}
private:
 int i;
};
---------------
file foo.C:
--------------
#include "headers.H"
Foo fooObj;

int Foo::foo_static_method() { return 2;}
--------------
file bar.C:
--------------
#include "headers.H"
Bar barObj;

int Bar::bar_static_method() { return 3;}





--
-- Joe Buck jbuck@synopsys.com
Posting from but not speaking for Synopsys, Inc.
Formerly jbuck@<various-hosts>.eecs.berkeley.edu