Nieodpowiednie wywołanie destruktorów w klasach dziedziczących z AVR-G++
AVR-G++ i blad kompilatora?
From: "T.M.F." <tfrancuz_at_nospam_nospam.mp.pl>
Subject: AVR-G++ i blad kompilatora?
Date: Fri, 24 Mar 2006 17:41:10 +0100
Jest sobie taki oto kod:
void * operator new(size_t size)
{
return malloc(size);
}
void operator delete(void * ptr)
{
free(ptr);
}
class One
{
char * txt;
public:
One() {txt=NULL;};
virtual char *GetName() {return "One";};
char *GetObjName() {return GetName();};
virtual ~One();
};
class Two : public One
{
char *txt1;
public:
Two() {txt1=NULL;};
virtual char *GetName() {return "Two";};
~Two();
};
One::~One()
{
if(txt) free(txt);
}
Two::~Two()
{
if(txt1) free(txt1);
}
int main(void)
{
volatile char *ret;
One *o1=new One();
Two *o2=new Two();
ret=o1->GetObjName();
ret=o2->GetObjName();
delete o1;
delete o2;
}
Wszystko jest ok, konstruktory sa wywolywane we wlasciwej kolejnosci,
ret prawidlowo zawiera zwracane nazwy obiektow. Problem zaczyna sie w
momencie wykonania instrukcji delete o1 i delete o2.
Okazuje sie, ze po delete o1 nie jest wywolywany destruktor obiektu One,
a po delete o2 jest wywolywany i owszem destruktor obiektu One, ale juz
nie jest wywolywany destruktor obiektu Two. Czyli program sie zachowuje
tak jakby wywolywany byl destruktor z obiektu "o jeden wczesniejszego" w
dziedziczeniu.
Czy ktos moglby to sprawdzic jeszcze u siebie? Moze to tylko blad
debuggera z AVR Studio?
Gdzie mozna zglaszac bledy kompilatora AVR-gcc/g++? Bo na stronie WinAVR
widze tylko mozliwosc zglaszania bledow zwiazanych z instalacja w
Windowsie.
--
Inteligentny dom - http://idom.wizzard.one.pl
Teraz takze forum dyskusyjne
Zobacz, wyslij uwagi, dolacz sie do projektu.
From: Marcin Stanisz <mstanisz_at_nospam_poczta.bzdury.onet.pl>
Subject: Re: AVR-G++ i blad kompilatora?
Date: Fri, 24 Mar 2006 18:12:44 +0100
Dnia Fri, 24 Mar 2006 17:41:10 +0100, T.M.F. napisał(a):
<ciach>
Gdzie mozna zglaszac bledy kompilatora AVR-gcc/g++? Bo na stronie WinAVR
widze tylko mozliwosc zglaszania bledow zwiazanych z instalacja w
Windowsie.
http://gcc.gnu.org/bugs.html
Napisali nawet coś na temat destruktorów (ale ja się na C++ kompletnie nie
znam ;>):
"Global destructors are not run in the correct order.
Global destructors should be run in the reverse order of their
constructors completing. In most cases this is the same as the reverse
order of constructors starting, but sometimes it is different, and that is
important. You need to compile and link your programs with
--use-cxa-atexit. We have not turned this switch on by default, as it
requires a cxa aware runtime library (libc, glibc, or equivalent)."
Jest jeszcze lista dyskusyjna o avr-gcc:
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Pozdrawiam
Marcin Stanisz
--
"A lie will go round the world before the truth has got its boots on"
Terry Pratchett, "Truth"