🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #53

Re: static vals inside a class are unresolved (g++ 2.0/SunOS4.1.1)

#53
From: Joe Buck
Date: Fri, 10 Apr 1992 23:49
53 lines
2185 bytes
In article <MCCRORY.92Apr10161734@tomato.fnal.gov> mccrory@tomato.fnal.gov (Elliott McCrory) writes:
>Seems like a kludge.  Why has static been abandoned?

static has not been abandoned; the change in g++-2.0 is that the
compiler now implements what Ellis and Stroustrup specify in the ARM.
In the example, the code was buggy, even though it compiled and ran
under old g++.  The code might or might not have linked successfully
under cfront; it depends on whether the C compiler underneath enforces
the "one definition" rule or not.  That is, in some C compilers if
a bunch of different files declare

extern int foo;

then no one has defined foo: it's an undefined symbol.  In others,
a definition of foo with value zero will appear.  But the ANSI C
standard calls for a definition for each object: a conforming program
has to have "int foo;" somewhere.

In the same way, for each static class variable declared in the class
definition there must exist somewhere an initializer for that variable.
Many compilers kludge one up if none is specified by using the "common
block" technique, but this is contrary to the ARM (think of it as an
extension g++ no longer supports).

If you say

class Bar {
	...
};

class Foo {
	...
	static Bar fooStaticMember;
};

you must, in some source file that includes Foo's definition, say

Bar Foo::fooStaticMember;

If you want to give arguments to the Bar constructor, say

Bar Foo::fooStaticMember(arg1,arg2,...);

If it's an integer, and you want to give a value, say

int Foo::fooStaticInt = 3;

or some such.



--
Joe Buck	jbuck@ohm.berkeley.edu
Technical Details
Message-ID: <s59ijINNg88@agate.berkeley.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!agate!forney.berkeley.edu!jbuck
References: <MCCRORY.92Apr9161630@tomato.fnal.gov> <1992Apr9.234910.7629@cco.caltech.edu> <MCCRORY.92Apr10161734@tomato.fnal.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!agate!forney.berkeley.edu!jbuck
From: jbuck@forney.berkeley.edu (Joe Buck)
Newsgroups: gnu.g++.help
Subject: Re: static vals inside a class are unresolved (g++ 2.0/SunOS4.1.1)
Date: 10 Apr 1992 23:49:39 GMT
Organization: University of California, Berkeley
Lines: 53
Distribution: gnu
Message-ID: <s59ijINNg88@agate.berkeley.edu>
References: <MCCRORY.92Apr9161630@tomato.fnal.gov> <1992Apr9.234910.7629@cco.caltech.edu> <MCCRORY.92Apr10161734@tomato.fnal.gov>
NNTP-Posting-Host: forney.berkeley.edu