Article View: gnu.g++.bug
Article #1117Bug in gcc 2.2.2 fuer C++ ??
From: Harald Leszke
Date: Mon, 09 Nov 1992 20:13
Date: Mon, 09 Nov 1992 20:13
275 lines
5876 bytes
5876 bytes
Hello!
I would like to implement an one time linked list in C++.
Every objekt is represented, by an struct 'node', containing data and link to
the next objekt.
By assigning '=' the list is set empty and the new nodes are copied.
'+=' means, the nodes of the second list are copied and concatenated to the
first list.
No problem using AT&T CC, but gcc has some serious problems at runtime.
Can anybody help ?
Any patch aviable ?
Thanks in advance.
Harald Leszke.
Runlisting:
Script started on Mon Nov 9 20:39:07 1992
warning: could not update utmp entry
21 (.../diploma/c++)>gcc -g -v gcc_test.cc
Reading specs from /usr/gnu/lib/gcc-lib/sun4/2.2.2/specs
gcc version 2.2.2
/usr/gnu/lib/gcc-lib/sun4/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g gcc_test.cc /usr/tmp/cca09048.i
GNU CPP version 2.2.2 (sparc)
/usr/gnu/lib/gcc-lib/sun4/2.2.2/cc1plus /usr/tmp/cca09048.i -quiet -dumpbase gcc_test.cc -g -version -o /usr/tmp/cca09048.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
as -o gcc_test.o /usr/tmp/cca09048.s
/usr/gnu/lib/gcc-lib/sun4/2.2.2/ld -e start -dc -dp /lib/crt0.o -L/usr/gnu/lib/gcc-lib/sun4/2.2.2 -L/usr/gnu/lib gcc_test.o -lgcc -lc -lg -lgcc
22 (.../diploma/c++)>a.out
Wenn man diese Printanweisung auskommentiert -> Bus Error.
Liste zwei:
100
99
98
Liste eins+zwei:
100
99
98
100
Die Liste hat nicht so viele Elemente!23 (.../diploma/c++)>
23 (.../diploma/c++)>/usr/lang/CC gcc
gcc_test.cc gcc_test.cc~ gcc_test.s
23 (.../diploma/c++)>/usr/lang/CC gcc_test.cc
24 (.../diploma/c++)>a.out
Wenn man diese Printanweisung auskommentiert -> Bus Error.
Liste zwei:
100
99
98
Liste eins+zwei:
100
99
98
100
99
98
25 (.../diploma/c++)>^Dexit
script done on Mon Nov 9 20:42:54 1992
Listing: ( Sorry comments and output in german language. )
========
#include<stdio.h>
#include<stdlib.h>
typedef int was;
class s_list {
private: struct node{
node *next;
was data;
};
private:
node *first;
node *last;
int members;
node *ack;
int ack_nr;
public:
s_list(); // Constructor.
~s_list(); // Destructor
was get(int);
void append(was);
s_list operator = (const s_list );
s_list operator += (const s_list );
};
s_list::s_list()
{
first=NULL;
last=NULL;
members=0;
ack=NULL;
ack_nr=0;
};
s_list::~s_list()
{
node *tmp1,*tmp2;
tmp1=first;
while(tmp1!=NULL)
{
tmp2=tmp1;
tmp1=(*tmp1).next;
delete(tmp2);
}
}
was s_list::get(int wo)
{
int count;
node *searchnode;
if (wo>members)
{
printf("Die Liste hat nicht so viele Elemente!");
exit(1);
};
if (wo<1)
{
printf("Die Liste hat keine Elemente vor 1!");
exit(1);
};
if (members==0)
{
printf("Die Liste ist leer!");
exit(1);
};
searchnode=first;
for(count=1; count <wo; count++) searchnode=(*searchnode).next;
return (*searchnode).data;
}
void s_list::append(was data)
{
node *tmp,*tmp2;
tmp2=last;
tmp=new (node) ;
(*tmp).data=data;
(*tmp).next=NULL;
if(last!=NULL)
{
(*last).next=tmp;
last=tmp;
}
else
{
last=tmp;
first=tmp;
ack=tmp;
ack_nr=1;
}
members++;
}
// insert fuegt an der Stelle ein, dh. insert(~,7) fuegt ~ bei 7 ein, das
// ehemalige Element 7 ist jetzt Nummer 8.
s_list s_list::operator += (const s_list ein)
{
node *tmpein;
if (ein.members==0) return *this;
tmpein=ein.first;
while(tmpein!=NULL)
{
append((*tmpein).data);
tmpein=(*tmpein).next;
}
return *this;
}
s_list s_list::operator = (const s_list ein)
{
node *tmpein;
// Lassen wir den alten Schrott im Speicher haengen, da er den Fehler nicht
// beruehert.
first=NULL;
last=NULL;
members=0;
ack=NULL;
ack_nr=0;
if (ein.members==0) return *this; // neues anhaengen
tmpein=ein.first;
while(tmpein!=NULL)
{
append((*tmpein).data);
tmpein=(*tmpein).next;
}
return *this;
}
main()
{
s_list eins,zwei;
int count;
for (count=0;count<3;count++)
{eins.append(100-count);};
printf("Comenting this line out -> Bus Error. \n");
zwei=eins; // Wird mit append zugewiesen tritt der Fehler
// nicht auf.
printf("Liste zwei:\n");
for (count=1;count<4;count++)
printf("%i\n",zwei.get(count));
zwei+=eins;
printf("Liste eins+zwei:\n");
for (count=1;count<7;count++)
printf("%i\n",zwei.get(count));
}
--
Harald Leszke,Goerzalle 131/305,D-1000 Berlin 45, Tel: +49 (0)30 8178570
Wer mit 18 noch kein Kommunist ist, hat kein Herz!
Und wer mit 28 noch Kommunist ist, hat keinen Verstand.
Technical Details
Message-ID:
<1992Nov9.201321.22871@cs.tu-berlin.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!spool.mu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.tu-berlin.DE!leszkeShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!spool.mu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.tu-berlin.DE!leszke From: leszke@cs.tu-berlin.DE (Harald Leszke) Subject: Bug in gcc 2.2.2 fuer C++ ?? Message-ID: <1992Nov9.201321.22871@cs.tu-berlin.de> Sender: gnulists@ai.mit.edu Organization: Techn. University of Berlin, Germany Distribution: gnu Date: Mon, 9 Nov 1992 20:13:21 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 276