I was going about my day earlier, when
spot sent me an IM asking for help with one of my favorite programs. Apparently, it was failing quite spectacularly on sparc, and he was having some trouble making the machine give useful debug data.
After a bit of hacking on it, I found this wonderful nugget: (
(cut for those that don't care) )
Comments 7
&pl->pd
makes me itch. Parens are your friends!
Reply
The real problem here is that what you wind up doing is
char buf[1024];
struct lose {
uint64_t x;
} *s;
uint64_t x;
s = (struct lose *)buf[1];
x = *s;
About which the C Standard sez:A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the pointed-to type, the behavior is undefined.
So really an implementation can do whatever it wants here. Most implementations just let it work. On SPARC you get a SIGBUS and your program dumps core and goes away.
Reply
Reply
The irony is wonderful. Too bad about the result.
Reply
Evar.
Reply
Leave a comment