home *** CD-ROM | disk | FTP | other *** search
- 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
- From: euamts@eua.ericsson.se (Mats Henricson)
- Newsgroups: comp.lang.c++
- Subject: Re: Initialization {} of Aggregates with Stati
- Message-ID: <1992Dec15.094709.5566@eua.ericsson.se>
- Date: 15 Dec 92 09:47:09 GMT
- References: <BzA5oG.Bwu@polstra.uucp>
- Sender: news@eua.ericsson.se
- Reply-To: euamts@eua.ericsson.se
- Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
- Lines: 76
- Nntp-Posting-Host: euas62c36.eua.ericsson.se
-
- In article Bwu@polstra.uucp, jdp@polstra.uucp (John Polstra) writes:
- #I'd like some opinions on something that the ARM doesn't seem to address
- #directly:
- #
- # struct X {
- # int a;
- # static int b;
- # int c;
- # };
- #
- # X foo = { 1, 3 };
- #
- #I believe that this is legal, and that foo.a and foo.c should get
- #the values 1 and 3, respectively. Static member b should remain
- #uninitialized by the code shown here; it would have to be defined
- #exactly once elsewhere in the program.
- #
- #ARM section 8.4.1 doesn't say such cases are illegal, but it doesn't really
- #say what to do about them either.
- #
- #Cfront, High C/C++, Microsoft C++ 7.0 seem to agree with me. Furthermore,
- #the class library provided by Microsoft relies on this behavior. G++ 2.3.2
- #for i386-att-sysv4 generates bad stuff that causes the assembler to become
- #indignant.
- #
- #Comments and/or ARM citations, anyone?
-
- I have a similar problem. Take a look at the code below:
-
- #include <iostream.h>
-
- class testbase
- {
- public:
- int y; // If I remove this line...
- };
-
- class test : public testbase
- {
- public:
- int myVal;
- const test* myNext;
- };
-
- const test t1 = {7,1,0}; // If I remove "7,"
- const test t2 = {7,2,&t1}; // If I remove "7," Then Error here
- const test t3 = {7,3,&t2}; // If I remove "7," Then Error here
-
- main()
- {
- cout << "t1.myVal:" << t1.myVal << endl;
- cout << "t1.myNext:" << (int)(t1.myNext) << endl;
- cout << "&t1:" << (int)&t1 << endl;
- cout << "t2.myVal:" << t2.myVal << endl;
- cout << "t2.myNext:" << (int)(t2.myNext) << endl;
- cout << "&t2:" << (int)&t2 << endl;
- cout << "t3.myVal:" << t3.myVal << endl;
- cout << "t3.myNext:" << (int)(t3.myNext) << endl;
- cout << "&t3:" << (int)&t3 << endl;
- }
-
- // I get:
- // line 17: error: bad initializer type for test::myVal:
- // const test * ( int expected)
-
- As you can see: if I remove the int y in testbase and remove the 7s
- that initializes it in the three statemants just above main(), I get
- two errors. I also read 8.4.1 in ARM, but my pathetic brain is just
- too simple to understand. Sorry.
-
- Sun C++ 2.1.
-
- Mats Henricson
- Ellemtel
- Stockholm
- Sweden
-