WinAVR i bledy zalezne od optymalizacji

Czesc,

mam taki oto fragment kodu kompilowany w WinAVR-20100110:

////////////////////////////////////////// struct _TestStruct { unsigned Flag :1; };

unsigned char TestByte; int TestInt;

TestByte = ((struct _TestStruct *)&TestInt)->Flag; ///////////////////////////////////////////

Po skompilowaniu z optymalizacja -O0, -O1 wszystko jest ok. Natomiast po skompilowaniu z optymalizacja -O1, -O2, -O3, -Os, kompilator wypisuje blad: "dereferencing type-punned pointer will break strict-aliasing rules". O co w tym chodzi?

Pzdr, Maciek

Reply to
Maciek
Loading thread data ...

Uzytkownik "Maciek" snipped-for-privacy@interia.pl napisal w wiadomosci news: snipped-for-privacy@h39g2000yqn.googlegroups.com...

Dodam tylko, ze gdy zmienna TestInt jest typu 'char' - blad sie nie pojawia. Blad dotyczy oczywiscie linii, w ktorej wartosc bitu Flag jest przepisywana do zmiennej TestByte.

Maciek

Reply to
Maciek

formatting link

Reply to
Arek

formatting link

czego? gcc -Wall -O2 -g strict_aliasing.c -o strict_aliasing strict_aliasing.c: In function ?main?: strict_aliasing.c:13: warning: dereferencing type-punned pointer will break strict-aliasing rules

czego? ./strict_aliasing Testbyte 0, Testint 1

czego? gcc -Wall -O1 -g strict_aliasing.c -o strict_aliasing

czego? ./strict_aliasing Testbyte 1, Testint 1

Zadanie domowe : Dowiedziec sie czym rozni sie kod wynikowy przy uzyciu optymalizacji -O1 a -O2?

Reply to
cepu69

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.