Article View: gnu.g++.bug
Article #1534Strange g++ feature/bug
From: "Douglas C. Schmidt"
Date: Mon, 21 Nov 1988 05:58
Date: Mon, 21 Nov 1988 05:58
56 lines
2050 bytes
2050 bytes
Hi,
I'm not sure if the following code works due to any intentional G++
design feature, but it is certainly interesting! I seem to be able to
create anonymous recursively defined structures, use casts to manage
dynamically created linked lists, and not have to worry about
introducing a conflicting type name into the global namespace. This
appears to solve a particularly nasty defect of C and C++, i.e.,
inability to hide type names inside of classes ( the Ada folks always
snicker at this flaw, unfortunately ).
Naturally, the AT&T translator chewed this up and spit it back out,
so I suspect it is *not* a planned and portable feature for G++?!
Doug
----------------------------------------
#include <stream.h>
class Linked_List {
private:
struct { // No name for struct
int i;
struct *link; // Anonymous recursive link field!
} *Head, *Temp;
public:
Linked_List ( int Size ) { // warning: completely brain-damaged code ahead!
Head = ( void * ) new char [ sizeof ( *Head ) ];
Head->i = 0;
Temp = Head;
for ( int i = 1; i < Size; i++ ) {
Temp->link = ( void * ) new char [ sizeof ( *Head ) ];
Temp = ( void * ) Temp->link;
Temp->i = i;
}
Temp->link = 0;
}
~Linked_List ( void ) { // Print out the contents of the anonymous list!
for ( Temp = ( void * ) Head; Temp; Temp = ( void * ) Temp->link ) {
cout << Temp->i << "\n";
}
}
};
main ( int, char *argv [ ] ) {
Linked_List List ( atoi ( argv [ 1 ] ) );
}
Technical Details
Message-ID:
<8811202158.aa07310@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%glacier.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%glacier.ics.uci.edu
From: schmidt%glacier.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: Strange g++ feature/bug
Message-ID: <8811202158.aa07310@PARIS.ICS.UCI.EDU>
Date: 21 Nov 88 05:58:44 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 56