[FFmpeg-devel] [PATCH] change one bit fields to unsigned

Erik Hovland erik
Wed Jul 9 01:02:23 CEST 2008

On Tue, Jul 08, 2008 at 11:07:42PM +0300, Uoti Urpala wrote:
> On Tue, 2008-07-08 at 21:48 +0200, Reimar D?ffinger wrote:
> > On Tue, Jul 08, 2008 at 12:30:46PM -0700, Erik Hovland wrote:
> > > The sign of one bit fields is entirely compiler dependent it seems. But
> > > it is a good idea to declare them as unsigned since gcc usually treats
> > > using just 'int' as signed.
> > 
> > Except 4.2.0 which treats them always as 0 (another 30 minutes wasted
> > due to a compiler bug back then).
> > In light of above, I wouldn't mind it, it seems more reliable, but the
> > question is why do you want this change? Why would it matter if it is
> > signed or unsigned?
> It avoids implementation-defined behavior. Converting an integer to a
> signed integer type when the value cannot be represented in that type is
> implementation-defined behavior (this differs from signed arithmetic
> where unrepresentable results are undefined behavior). Thus "s.flag = 1"
> has implementation-defined behavior if "flag" is a signed bitfield of
> width 1.

I couldn't have said it better.

I have a secondary reason. When gcc encounters one bit fields that
use a signed type it emits a parsing warning. That warning causes extra
code to fire which makes the compiler work a bit harder. Making them
unsigned doesn't emit this warning and gcc chugs along a touch faster.

But this is probably only a marginal improvement in compile time


Erik Hovland
mail: erik at hovland.org
web: http://hovland.org/
PGP/GPG public key available on request

More information about the ffmpeg-devel mailing list