[PATCH] fix KJS crash on some more strict platforms

Maks Orlovich mo002j at mail.rochester.edu
Tue Dec 16 23:30:42 GMT 2003


>
> 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".

Ahem. Read a bit further. "A character type may alias any other type. "

And a bit further than that:
Pay special attention to code like this: 


        union a_union {
          int i;
          double d;
        };



 
        int f() {
          a_union t;
          t.d = 3.0;
          return t.i;
        }



 The practice of reading from a different union member than the one most 
recently written to (called ``type-punning'') is common. Even with 
-fstrict-aliasing, type-punning is allowed, provided the memory is accessed 
through the union type.










More information about the kde-core-devel mailing list