tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Bug Report (offset+cast)


From: Dave Dodge
Subject: Re: [Tinycc-devel] Bug Report (offset+cast)
Date: Fri, 11 May 2007 15:01:36 -0400
User-agent: Mutt/1.5.12-2006-07-14

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]