[FFmpeg-devel] [PATCH 3/7] Add alias-safe union typedefs

Michael Niedermayer michaelni
Sun Jan 31 14:08:15 CET 2010

On Fri, Jan 29, 2010 at 11:06:15AM +0000, M?ns Rullg?rd wrote:
> Michael Niedermayer <michaelni at gmx.at> writes:
> > On Fri, Jan 29, 2010 at 02:12:10AM +0000, Mans Rullgard wrote:
> >> ---
> >>  libavutil/intreadwrite.h |   18 ++++++++++++++++++
> >>  1 files changed, 18 insertions(+), 0 deletions(-)
> >
> > I belive these types would be usefull to projects using libavutil
> Here we go again...
> Those rely on the may_alias attribute being supported, which is tested
> by configure.  I guess it could be changed to check for gcc version
> instead, although that is less reliable with non-gcc compilers.

After looking in the c spec ..
why do we need may_alias at all? a union should be enough or am i missing

That said, these unions only need a char array as a char access can alias
anything. Otherwise if iam wrong they need float & double too

And with gcc a much better solution is along the lines of

#define UD(v,access)\
    ((union {\
        access a;\
        typeof(v) b[sizeof(access)/sizeof(typeof(v))];\

this specifies only the effective type + the accesed type and thus reduces
the restrictions placed on the optimizer.
It also shows how ridiculous this is as the compiler clearly knows the types


Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100131/8a04ec35/attachment.pgp>

More information about the ffmpeg-devel mailing list