[FFmpeg-devel] [PATCH] change one bit fields to unsigned
Uoti Urpala
uoti.urpala
Tue Jul 8 22:07:42 CEST 2008
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.
GCC defines this implementation-defined case to reduce the value mod
2^width, so that 4.2.0 behavior was a real bug (it should have produced
-1 rather than 0).
More information about the ffmpeg-devel
mailing list