AVR-G++ i blad kompilatora?

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.

Reply to
T.M.F.
Loading thread data ...

Dnia Fri, 24 Mar 2006 17:41:10 +0100, T.M.F. napisał(a): <ciach>

formatting link
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:

formatting link
Pozdrawiam Marcin Stanisz

Reply to
Marcin Stanisz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.