Failure of \"long x(cp) char * cp; { return *((long *) cp); }\" is a bug?

VLD/VMB gwyn at BRL.ARPA
Mon Jun 30 04:43:08 AEST 1986


No, it's not a bug; interpreting an arbitrary address as that of a long
integer is simply meaningless on most machines (the VAX is a rare exception).
The machine code that uses such an address to reference a long integer
datum generally traps the operation as an error.

Moving the data somewhere else with an aligned address of course works;
but the compiler can't do that for you, since casting a pointer to
another type should not cause data movement.  The compiler is bound by
the spirit of C to do its best to perform exactly the operation you
specify, not to reinterpret it as something more complicated and then
shuffle things around "behind the scenes" to try to "help" you out.



More information about the Comp.lang.c mailing list