This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/17170] -Wdefault-bitfield-sign


------- Additional Comments From terra at gnome dot org  2004-08-31 15:42 -------
I did a crude grep-scan on a 2.4.x linux kernel and found ~50 1-bit bitfields
that were signed by default.  A previous scan on parts of Gnome revealed a
similar number.  In other words, that kind of code is quite common.

Virtually all of these were being used as booleans, i.e., the programmer really
intended a field that could take the values 0 and 1.  Now on a two-complement
machine the field ended up holding 0 or -1 so depending on how the values read
were actually used, things might have worked.  Or not.  Hence the need for a
warning.

I cannot think of a case where one would want a signed one-bit bitfield, but
adding the explicit "signed" would make it clear that the programmer thought
about it.

(In C99 one would use a _Bool fields, but it'll be a few years before everyone
will have compilers that handle that right.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]