On Fri, May 11, 2007 at 03:32:47PM -0400, David A. Wheeler wrote:
> Dave Dodge:
> > Well, the term "correctly" is a bit suspect. You can't convert an
> > arbitrary char* to a short* and dereference it without risking
> > undefined behavior, because among other things there's no guarantee
> > that the pointed-to location will be aligned properly as a short.
[...]
> It'd be wiser to rewrite that code (e.g., as a memcpy to a short
> which you KNOW it's aligned), since no matter what it's non-portable.
Yeah that's probably how I'd do it.
Aside: from a purely C standpoint the memcpy() solution isn't actually
guaranteed to work either, thanks to C99's concept of padding bits. I
don't know of any real hardware where it would actually break, though,
and if such a system does exist it's almost certainly some weird
DSP/ASIC where if you're writing code for it you already know about
these issues.
-Dave Dodge
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel