[New-bugs-announce] [issue10310] signed:1 bitfields rarely make sense

Hallvard B Furuseth report at bugs.python.org
Thu Nov 4 12:51:20 CET 2010


New submission from Hallvard B Furuseth <h.b.furuseth at usit.uio.no>:

In Python 2.7 and 3.2a3, Modules/_io/textio.c uses signed:1 bitfields.

They have value -1 or 0 in two's complement, but are not used thus here:
gcc complains of <bitfield> = 1 overflow.  If the point was that they
are assigned signed values, well, unsigned:1 is promoted to signed int.

I also fix a strange (int) cast doing (truncate flag to int) & 1.
My guess is someone shut up a compiler warning about the above,
by cleaning up in the wrong place.  I kept a cast in case that's
not it, and some compiler would get noisy anyway.

There are possibly-signed 1-bit fields Modules/_ctypes/_ctypes_test.c:
struct BITS too, but I don't know what that code is for.  It does not
specify signedness of the bitfields, which (as with char) makes it the
compiler's choice.  That's usually a bad idea, but maybe that code is
for exploring the compiler?

----------
components: IO
files: signed-1-bitfield.diff
keywords: patch
messages: 120392
nosy: hfuru
priority: normal
severity: normal
status: open
title: signed:1 bitfields rarely make sense
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file19487/signed-1-bitfield.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10310>
_______________________________________


More information about the New-bugs-announce mailing list