home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17972 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.7 KB  |  90 lines

  1. Path: sparky!uunet!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!usc!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!ericom!eua.ericsson.se!euas62c36!euamts
  2. From: euamts@eua.ericsson.se (Mats Henricson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Initialization {} of Aggregates with Stati
  5. Message-ID: <1992Dec15.094709.5566@eua.ericsson.se>
  6. Date: 15 Dec 92 09:47:09 GMT
  7. References: <BzA5oG.Bwu@polstra.uucp>
  8. Sender: news@eua.ericsson.se
  9. Reply-To: euamts@eua.ericsson.se
  10. Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
  11. Lines: 76
  12. Nntp-Posting-Host: euas62c36.eua.ericsson.se
  13.  
  14. In article Bwu@polstra.uucp, jdp@polstra.uucp (John Polstra) writes:
  15. #I'd like some opinions on something that the ARM doesn't seem to address
  16. #directly:
  17. #
  18. #    struct X {
  19. #    int a;
  20. #    static int b;
  21. #    int c;
  22. #    };
  23. #
  24. #    X foo = { 1, 3 };
  25. #
  26. #I believe that this is legal, and that foo.a and foo.c should get
  27. #the values 1 and 3, respectively.  Static member b should remain
  28. #uninitialized by the code shown here; it would have to be defined
  29. #exactly once elsewhere in the program.
  30. #
  31. #ARM section 8.4.1 doesn't say such cases are illegal, but it doesn't really
  32. #say what to do about them either.
  33. #
  34. #Cfront, High C/C++, Microsoft C++ 7.0 seem to agree with me.  Furthermore,
  35. #the class library provided by Microsoft relies on this behavior.  G++ 2.3.2
  36. #for i386-att-sysv4 generates bad stuff that causes the assembler to become
  37. #indignant.
  38. #
  39. #Comments and/or ARM citations, anyone?
  40.  
  41. I have a similar problem. Take a look at the code below:
  42.  
  43. #include <iostream.h>
  44.  
  45. class testbase 
  46. {
  47.    public:
  48.       int y;               // If I remove this line...
  49. };
  50.  
  51. class test : public testbase 
  52. {
  53.    public:
  54.       int myVal;
  55.       const test* myNext;
  56. };
  57.  
  58. const test t1 = {7,1,0};      // If I remove "7,"
  59. const test t2 = {7,2,&t1};    // If I remove "7,"  Then Error here
  60. const test t3 = {7,3,&t2};    // If I remove "7,"  Then Error here
  61.  
  62. main()
  63. {
  64.     cout << "t1.myVal:" << t1.myVal << endl;
  65.     cout << "t1.myNext:" << (int)(t1.myNext) << endl;
  66.     cout << "&t1:" << (int)&t1 << endl;
  67.     cout << "t2.myVal:" << t2.myVal << endl;
  68.     cout << "t2.myNext:" << (int)(t2.myNext) << endl;
  69.     cout << "&t2:" << (int)&t2 << endl;
  70.     cout << "t3.myVal:" << t3.myVal << endl;
  71.     cout << "t3.myNext:" << (int)(t3.myNext) << endl;
  72.     cout << "&t3:" << (int)&t3 << endl;
  73. }    
  74.  
  75. // I get:
  76. // line 17: error: bad initializer type for test::myVal:
  77. //          const test * ( int  expected)
  78.  
  79. As you can see: if I remove the int y in testbase and remove the 7s
  80. that initializes it in the three statemants just above main(), I get
  81. two errors. I also read 8.4.1 in ARM, but my pathetic brain is just
  82. too simple to understand. Sorry.
  83.  
  84. Sun C++ 2.1.
  85.  
  86. Mats Henricson
  87. Ellemtel
  88. Stockholm
  89. Sweden
  90.