
converting an char pointer to an integer pointer
Hello all
I assume that the following
char *p;
/* p is assigned memory here */
*(int *) p = 42;
should cause UB, but I cannot find a reference in the c99
standard (dont have c89) which covers the conversion of
a pointer to an integer type being converted to a pointer
to another integer type of higher rank.
The above code generates a trap on the m68k architecture.
The reference that I have found in the standard is
6.3.1.3 #3 and 6.2.5 #6, which says that a trap *can* be
raised by the implementation if the value cannot be
represented, and that differently ranked integer types
can have different alignments.
anything in the standard (either one) specifically
prohibits the above piece of code ?
(btw: I did not write the offending code, I was merely
given the piece of code and asked what was wrong with
it. I am currently trying to get everyone I work
with to adhere to c89)
goose,
trying to rid the world of UB