Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!uw-beaver!ubc-vision!alberta!calgary!lomow From: lomow@calgary.UUCP Newsgroups: comp.lang.c++ Subject: Bug in C++ 1.2 involving the :: operator Message-ID: <867@vaxb.calgary.UUCP> Date: Sat, 4-Apr-87 08:47:34 EST Article-I.D.: vaxb.867 Posted: Sat Apr 4 08:47:34 1987 Date-Received: Sun, 5-Apr-87 22:51:29 EST Distribution: na Organization: U. of Calgary, Calgary, Ab. Lines: 110 Keywords: also a question of style I have found a bug in release 1.2 of C++. Could you please look at the following description of the problem and either confirm or clear up the problem. I'm sorry if this problem has been previously reported, but it is new to me. The following program ////////// #include #define NULL 0 class q_el { q_el *Next; public: q_el *next() { return Next;} q_el(q_el *n) { Next=n; } }; class d_q_el : public q_el { int Count; public: int count() { return Count;} d_q_el(q_el *n, int c) : (n) { Count = c; } }; main() { q_el *q; q = new d_q_el(NULL, 2); // will be at the end of the list q = new d_q_el(q, 1); // will be at the head of the list if ( ((d_q_el*)q) ->count() == 1) printf("ok\n"); if ( ((d_q_el*)q->next()) ->count() == 2) printf("ok\n"); if (q->d_q_el::count() == 1) printf("ok\n"); // *** the following line causes an internal error **** if (q->next()->d_q_el::count() == 2) printf("ok\n"); } ////////// causes the compiler to issue the following messages: % CC c.err.c CC c.err.c: "c.err.c", line 31: internal <> error: bus error (or something nasty like that) 1 error % The problem seems to be the use of the scope resolution operator (i.e., '::') with a result returned from a function (or maybe it has to do with the way inline functions are expanded). The error can be eliminated by: 1) Commenting out line 30 (the line before the closing curly bracket of main()). or 2) Making Next a public data member of q_el and changing the calls to next() in main() to references to the variable Next - as shown in the following program. ////////// #include #define NULL 0 class q_el { public: q_el *Next; // MOVED q_el *next() { return Next;} q_el(q_el *n) { Next=n; } }; class d_q_el : public q_el { int Count; public: int count() { return Count;} d_q_el(q_el *n, int c) : (n) { Count = c; } }; main() { q_el *q; q = new d_q_el(NULL, 2); q = new d_q_el(q, 1); if (((d_q_el*)q)->count() == 1) printf("ok\n"); if (((d_q_el*)q->Next)->count() == 2) printf("ok\n"); // CHANGED if (q->d_q_el::count() == 1) printf("ok\n"); if (q->Next->d_q_el::count() == 2) printf("ok\n"); // CHANGED } ////////// I prefer the following style if (q->next()->d_q_el::count() == 2) printf("ok\n"); to if ( ((d_q_el*)q->next()) ->count() == 2) printf("ok\n"); because the cast in the second if statement is hard to read. Would anyone care to comment? are there other alternatives? Thank You, Greg Lomow. Usenet: ....![ubc-vision,ihnp4]!alberta!calgary!lomow