Bruce Momjian wrote:According to the C standard, it's illegal to access a data with a pointer of the wrong type. The only exception is "char *".
This seems to be a bug in gcc-3.3.1. -fstrict-aliasing is enabled by -O2 or higher optimization in gcc 3.3.1.
This can be used by compilers to pipeline loops, or to reorder instructions.
For example
void dummy(double *out, int *in, int len) { int j; for (j=0;j<len;j++) out[j] = 1.0/in[j]; }
Can be pipelined if a compiler relies on strict aliasing: it's guaranteed that writing to out[5] won't overwrite in[6].
I think MemSet violates strict aliasing: it writes to the given address with (int32*). gcc might move the instructions around.
I would disable strict aliasing with -fno-strict-aliasing.
In the Linux kernel, you can see this in include/linux/tcp.h:
/* * The union cast uses a gcc extension to avoid aliasing problems * (union is compatible to any of its members) * This means this part of the code is -fstrict-aliasing safe now. */
The kernel is still compiled with -fno-strict-aliasing - I'm not sure if there are outstanding problems, or if it's just a safety precaution.
-- Manfred
---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])