[FFmpeg-devel] pre discussion around Blackfin dct_quantize_bfin routine
Marc Hoffman
mmhoffm
Tue Jun 12 17:49:30 CEST 2007
On 6/12/07, Uoti Urpala <uoti.urpala at pp1.inet.fi> wrote:
> 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.
Thanks, I'm going to use it because the other stuff doesn't work as I
expected. I filed a bug wth the maintainer of the compiler so that it
can be corrected. Thanks. Marc
More information about the ffmpeg-devel
mailing list