[PATCH] fix KJS crash on some more strict platforms

Helge Deller deller at gmx.de
Tue Dec 16 23:11:31 GMT 2003

On Wednesday 17 December 2003 00:00, Maks Orlovich wrote:
> > > union { char NaN_Bytes[8];
> > > 	double NaN_Double;
> > > 	} NaN_Representation;
> > >
> > > which presumably forces the whole union to the alignment of the strictest
> > > type. Neater than using a gcc extension.
> >
> > Newer gcc's (e.g. 3.3.x) does not guarantee that this will work under all
> > circumstances and would force you to compile with  -fno-strict-aliasing.
> Huh? Accessing fields of unions is perfectly legal. In fact you don't even 
> need the union to access something through a char*

The compiler might align char[] and double in _this_ example differently, e.g.
char[] at a 2 byte boundary and double at 8 bytes.
Look at the manpage of gcc (e.g. http://scv.bu.edu/SCV/Archive/linux-cluster/manpages/gcc.html
and search for the example in the description for "-fstrict-aliasing"):
"In particular, an object of one type is assumed never to reside at the same address as an object 
of a different type, unless the types are almost the same. For example, an "unsigned int" can 
alias an "int", but not a "void*" or a "double""

char[] and double are not "almost the same".

More information about the kde-core-devel mailing list