🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #843

Re: static member bug

#843
From: Mike Stump
Date: Sat, 29 Aug 1992 14:56
74 lines
2253 bytes
You and hundreds of other have found this ``bug,'' the only problem
is, this is not a bug.  Please consult a recent book on c++ on how to
specify the definition for a static data member of a class.

(Hint:  Looks like int Class::Member = 4; outside the class's {})

> From: grosjean@masi.ibp.fr (Christophe GROSJEAN)
> Message-Id: <9207301247.AA01155@cao-vlsi.ibp.fr>
> To: bug-gcc@prep.ai.mit.edu
> Date: Thu, 30 Jul 92 13:44:48 BST

> I think i have found a bug with g++.  Static data members compile
> well but don't link.  It seems the job is done, except that compiler
> wont allocate space for that kind of data This problem appears with
> g++ 2.2.2 and 2.1. on SparcStation under SunOs 4.1.1.

> Below is a small sample program showing off the problem :

> ---------------------------------------------
> #include <stdio.h>

> class Bug 
> {
> 	public:
> 	static int i = 0;
> 	Bug() {	printf("%d ",i++); }
> };


> main()
> {
> 	Bug b;
> 	Bug c;
> 	Bug d;
> }
> -----------------------------------------

> (yes, I know i should use streams for I/O, but that's not the point...)

> When I compile this code (it provide a class that counts it's instances)

> I get the message :

> ld: Undefined symbol
> 	__3Bug$i

> I think it's a major problem, 'cause static members are the only clean way
> to implement shared data between every members of a class.

> Still, i've found a way (a very very dirty way...) to patch the problem
> so i can go with it.
> However, you'll understand that i'm not quite satifsfied...

> The following code will compile, link and work perfectly...

> ----------------------------------------------------
> #include <stdio.h>

> static int _3Bug$i = 0;

> class Bug 
> {
> 	public:
> 	static int i = 0;
> 	Bug() {	printf("%d ",i++); }
> };


> main()
> {
> 	Bug b;
> 	Bug c;
> 	Bug d;
> }
Technical Details
Message-ID: <9208291456.AA29434@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Subject: Re:  static member bug
Message-ID: <9208291456.AA29434@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 29 Aug 1992 14:56:22 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 75