Elmar Krieger writes:
>
> I searched hard, but couldn't determine conclusively if the C standard
> allows to alias a void* pointer with a char* pointer.
>
> If that's not undefined behavior, then the following may be a glitch in
> GCC 4.1.0 when compiled with -O2.
>
> Here's the ugly minimal piece of code:
>
> /* ASSUME pointer POINTS TO AN INTEGER THAT SPECIFIES THE INCREMENT
> ================================================================ */
> int increment(int *pointer)
> { return(*pointer); }
>
> /* INCREMENT A POINTER BY THE NUMBER OF BYTES POINTED TO
> ===================================================== */
> void *incremented(void *pointer)
> { int inc=increment(pointer);
> *((char**)&pointer)+=inc;
Not legal C. Do
pointer = (char*)pointer + inc;
Andrew.