home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!cis.ohio-state.edu!masi.ibp.fr!grosjean
- From: grosjean@masi.ibp.fr (Christophe GROSJEAN)
- Subject: static member bug
- Message-ID: <9207301247.AA01155@cao-vlsi.ibp.fr>
- Sender: gnulists@ai.mit.edu
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Thu, 30 Jul 1992 12:44:48 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 97
-
- Hello Everyone,
-
- 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;
- }
-
- ----------------------------------------------------
-
- Thanks for fixing problem...
-
-
-
-
-
-
- --
-
- _-----_
- / ) \
- ( ) )
- \/ \ / \/
- +---+ \ | / Christophe GROSJEAN
- / \ / \ \/|\/
- / / \ \O/ Equipe CAO&VLSI
- +---+ \ \ /H\ Laboratoire MASI
- \ \ +---+ / \ Institut Blaise Pascal
- \ / /
- \ / \ / Couloir 55-65, 2eme etage, Bureau 201
- +---+ Universite Pierre et Marie Curie (P6)
- 4 place Jussieu, 75252 Paris Cedex 05
-
- Tel: 44.27.30.43, Fax: 44.27.62.86
- Telex: UPMCSIX200145F, e-mail: kriss@masi.ibp.fr
- .
-
-
-