🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Christophe GROSJEAN Thu, 30 Jul 1992 12:44
static member bug
#337
Author: Christophe GROSJEAN
Date: Thu, 30 Jul 1992 12:44
95 lines
2537 bytes
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
. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads