Compatibility issue with 2.2.19pre7
Andrea Arcangeli <[email protected]>:
Quoted 15 lines · Richard Henderson
Quoted 9 lines · Andrea Arcangeli
Quoted 8 lines
What I said is that I can write this C code:
int x[2], * p = (int *) (((char *) &x)+1); main() { *p = 0; }Quoted 4 lines
Quoted 1 line
This is legal C code.
Err, no. This is not "legal" by any stretch of the imagination. This code has undefined behaviour.
Quoted 6 lines
I know this code has undefined behaviour at _runtime_. But I thought you were obliged to allow it to compile. That was my only point.
Quoted 1 line
We aren't even obliged to allow this to compile.
I'd love if you could forbid it to compile.
It would have to be implementation dependant/architecture dependant- The only way to know is to realize that *p initializer value is invalid is to know:
1. integer addresses MUST be aligned (say 4 or 8 byte boundaries)
2. the computation of (int *) (((char *) &x)+1) is a constant at compile time, and not link time (some linkers can do address offset calculations if "x" happens to be an external - ie. x +/- offset and offset is a constant)
Other systems would have to allow it to compile (and link). It still has undefined behaviour, and is non-portable.
-------------------------------------------------------------------------
Jesse I Pollard, II
Email: [email protected]
Any opinions expressed are solely my own.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/