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

Måns Rullgård mans
Sun Jan 31 14:48:22 CET 2010


Michael Niedermayer <michaelni at gmx.at> writes:

> 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
> something?

You're missing gcc.

> 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))];\
>     }*)(v))->a

Aaaaiiiieeee!

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list