This is the mail archive of the gcc@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]

Re: Wishlish: GCC option for explicit booleans


* Peter Lupton NCH Swift Sound <pl@nch.com.au> [051002 05:47]:
> I was hoping was that we could at least have a compile option. So we could 
> turn it on if required. I would definitely mandate it in our organization 
> at least. I am sure others would too.

I'd looked into getting some boolean checking into the C compiler (I am
personally not that interested in C++), but gcc has this "truthvalues are ints" 
quite heavily built in (which is not very suprising, after all the standard says
the are).
Attached is a experimental patch to make the C compiler do boolean checking
by making truthvalues of type bool instead of int and checking for them.
This definitly breaks the standard, as it changed the actual type.
It would be much nicer if there was some kind of "shadow types", that
would be only used for some additional warnings and not for code
generation. That way I think it would still be C standard conform, but
having looked only a very little into the gcc source, I cannot even
guess if it is possible and how much time it would need to implement
that.
While the patch cleary shows my little knowledge of the gcc code, and
switches truthvalue checking on unconditionally (and changes C
semantics, so I really suggest to not use it for anything but type
checking), it found some bugs in code I checked with it. (Which of
course already was written in a way it keeps truthvalues and integers
seperate, such a feature is only sensible if you have such a policy from
the start).
It also has suprisingly few false positives, once one
#define __builtin_expect(a,b) (a)
#define __builtin_constant_p(a) (__builtin_constant_p(a) != 0)
and encapsulates all ctype.h functions...

Hochachtungsvoll,
	Bernhard R. Link

Attachment: bool-patch.20051002
Description: Text document


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