home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 2023 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.4 KB  |  110 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!masi.ibp.fr!grosjean
  3. From: grosjean@masi.ibp.fr (Christophe GROSJEAN)
  4. Subject: static member bug
  5. Message-ID: <9207301247.AA01155@cao-vlsi.ibp.fr>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 30 Jul 1992 12:44:48 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 97
  12.  
  13. Hello Everyone, 
  14.  
  15. I think i have found a bug with g++.
  16. Static data members compile well but don't link.
  17. It seems the job is done, except that compiler wont allocate space for that kind of data
  18. This problem appears with g++ 2.2.2 and 2.1. on SparcStation under SunOs 4.1.1.
  19.  
  20.  
  21. Below is a small sample program showing off the problem :
  22.  
  23. ---------------------------------------------
  24. #include <stdio.h>
  25.  
  26. class Bug 
  27. {
  28.     public:
  29.     static int i = 0;
  30.     Bug() {    printf("%d ",i++); }
  31. };
  32.  
  33.  
  34. main()
  35. {
  36.     Bug b;
  37.     Bug c;
  38.     Bug d;
  39. }
  40. -----------------------------------------
  41.  
  42. (yes, I know i should use streams for I/O, but that's not the point...)
  43.  
  44. When I compile this code (it provide a class that counts it's instances)
  45.  
  46. I get the message :
  47.  
  48. ld: Undefined symbol
  49.     __3Bug$i
  50.  
  51. I think it's a major problem, 'cause static members are the only clean way
  52. to implement shared data between every members of a class.
  53.  
  54. Still, i've found a way (a very very dirty way...) to patch the problem
  55. so i can go with it.
  56. However, you'll understand that i'm not quite satifsfied...
  57.  
  58. The following code will compile, link and work perfectly...
  59.  
  60. ----------------------------------------------------
  61. #include <stdio.h>
  62.  
  63. static int _3Bug$i = 0;
  64.  
  65. class Bug 
  66. {
  67.     public:
  68.     static int i = 0;
  69.     Bug() {    printf("%d ",i++); }
  70. };
  71.  
  72.  
  73. main()
  74. {
  75.     Bug b;
  76.     Bug c;
  77.     Bug d;
  78. }
  79.  
  80. ----------------------------------------------------
  81.  
  82.     Thanks for fixing problem...
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. -- 
  90.     
  91.                      _-----_ 
  92.                     /   )   \
  93.                    (    )    )
  94.                     \/ \ / \/
  95.        +---+         \  |  /       Christophe GROSJEAN
  96.       / \ / \         \/|\/
  97.      /   /   \         \O/             Equipe CAO&VLSI
  98.     +---+ \   \        /H\            Laboratoire MASI
  99.      \   \ +---+       / \      Institut Blaise Pascal
  100.       \   /   /
  101.        \ / \ /   Couloir 55-65, 2eme etage, Bureau 201
  102.         +---+    Universite Pierre et Marie Curie (P6)
  103.                  4 place Jussieu, 75252 Paris Cedex 05
  104.  
  105.    Tel: 44.27.30.43,         Fax: 44.27.62.86
  106.    Telex: UPMCSIX200145F, e-mail: kriss@masi.ibp.fr
  107.  
  108.  
  109.