[FFmpeg-devel] [PATCH 3/7] Add alias-safe union typedefs
Mon Feb 1 00:31:55 CET 2010
On Sun, 2010-01-31 at 15:56 -0500, Alexander Strange wrote:
> It's not legal to cast a pointer like that, so any type cast without extra attributes can't work with strict aliasing:
> C99 188.8.131.52 p7:
> 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. Otherwise, when converted back again, the result shall compare equal to the original pointer. When a pointer to an object is
> converted to a pointer to a character type, the result points to the lowest addressed byte of the object. Successive increments of the result, up to the size of the object, yield pointers to the remaining bytes of the object.
There's the alignment issue that I mentioned in my previous mail, but if
the address happens to be suitably aligned then nothing here should
prevent the cast.
> There's no text about dereferencing a converted pointer, so it's undefined.
The above paragraph talks about the conversions only and doesn't seem to
be relevant to dereferencing. I looked at the thread you linked below
and there some expressed claims that this would limit dereferencing, but
I find that to be a somewhat weird interpretation. At least that would
IMO be somewhat impractical.
> It's also forbidden in the gcc manual:
> There's a long recent gcc thread about this here:
> Casts with may_alias were found to work for x264, but the portable solution is probably either no strict aliasing or using memcpy().
Why would no strict aliasing be more portable than may_alias?
More information about the ffmpeg-devel