[FFmpeg-devel] pre discussion around Blackfin dct_quantize_bfin routine

Uoti Urpala uoti.urpala
Tue Jun 12 16:17:53 CEST 2007


On Tue, 2007-06-12 at 14:17 +0100, M?ns Rullg?rd wrote:
> > +static inline uint64_t read_time(void)
> > +{
> > +    union {
> > +        struct {
> > +            unsigned lo;
> > +            unsigned hi;
> > +        } p;
> > +        unsigned long long c;
> > +    } t;
> > +    asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
> > +    return t.c;
> > +}
> 
> Using unions like that isn't allowed by the C standard.  It usually works,
> but there are no guarantees.  In fact, I've seen such things break in nasty
> ways.

What use do you mean by use "like that"? That doesn't seem like a
particularly dangerous construct. Assuming that you know the platform
endianness, type sizes and layout for the struct I don't notice anything
likely to cause problems in practice. Even with -fstrict-aliasing such
type punning which explicitly uses the union fields should work.





More information about the ffmpeg-devel mailing list