gwyn@BRL.ARPA (VLD/VMB) (06/29/86)
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.
rgenter@BBN-LABS-B.ARPA (Rick Genter) (06/29/86)
I don't think you can call that a compiler bug. There are machines where
returning the long pointed at by a character pointer makes no sense (e.g.,
PDP-10). This is one of those cases that lint calls questionable, and
rightfully so.
In any case, you provided a cast, which implies that "you know what you are
doing." It's no more a compiler bug for your example to trap than it is for
main ()
{
* (long *) main = 0x12345678;
}
to trap on any machine that protects text space from user writes.
--------
Rick Genter BBN Laboratories Inc.
(617) 497-3848 10 Moulton St. 6/512
rgenter@labs-b.bbn.COM (Internet new) Cambridge, MA 02238
rgenter@bbn-labs-b.ARPA (Internet old) linus!rgenter%BBN-LABS-B.ARPA (UUCP)