This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
int vs. bool / _Bool (Was: Re: Committed: Fix distribute_loop)
- From: Joern Rennecke <amylaar at spamcop dot net>
- To: Richard Guenther <richard dot guenther at gmail dot com>
- Cc: Paolo Bonzini <bonzini at gnu dot org>, gcc at gcc dot gnu dot org
- Date: Sat, 23 Jan 2010 09:21:47 -0500
- Subject: int vs. bool / _Bool (Was: Re: Committed: Fix distribute_loop)
- References: <20100123073057.pzhu5vatj40sw44w-nzlynne@webmail.spamcop.net> <84fc9c001001230436p623c7d26q78ba3621718955cc@mail.gmail.com> <4B5AFB88.6030803@gnu.org> <84fc9c001001230541t58c96b77l115af2dafc5ea938@mail.gmail.com>
[This started on gcc-patches]
Quoting Richard Guenther <richard.guenther@gmail.com>:
On Sat, Jan 23, 2010 at 2:37 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
On 01/23/2010 01:36 PM, Richard Guenther wrote:
Ugh. ÂI wonder if we should use _Bool instead of int
if the host compiler supports it.
Then we'd have another share of bugs if someone uses
Âbool a = <something evaluating to 2>;
Âa &= <something evaluating to 1>;
We do have those already. I run over this recently:
bool all_critical_edge_p = true;
all_critical_edge_p &= e->flags & EDGE_CRITICAL;
with _Bool this would work as expected, with ints it doesn't. With
C++ it would work as well.
Another option would be to stop using bool - as our bool doesn't have
the same semantics as bool in C++ or _Bool in C99. Which can
be surprising.
I think a better long-term plan would be to add an option to insert run-time
checks to abort when a integer other than 0 or 1 is converted to bool / _Bool.
We could then use this in gcc builds when enable-checking is active.
Or we could add a warning option for any int -> bool/_Bool conversion, but
this could cost some extra GCC runtime overhead as some places will need to
add some_integer != 0 checks to silence the warning, even though some_integer
might be known to always be either 0 or 1.