Wishlish: GCC option for explicit booleans
Peter Lupton NCH Swift Sound
pl@nch.com.au
Sun Oct 2 03:41:00 GMT 2005
Hi Andrew,
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.
We have a prepared list of common errors C++ novices make and the
accidental boolean is always near the top. This is one that is so easily
resolvable without any significant performance or compatibility issues.
At 01:07 PM 2/10/2005, you wrote:
> > C++ would be a better language if the boolean type did not implicitly
> > convert from int. For example, many novice programmers make the
> > mistake.
> >
> > if (i = j) dosomething(); // Should be i == j
> >
> > If conversion to boolean required explicit this would all be solved. It
> > would mean all the old code with expressions like "while (p) ... "
> > would need to be changed to "while (p != NULL) ...". But I think the
> > change would be well justified.
> >
> > What about a GCC option to turn off implicit conversion to boolean?
>
>GCC has an option to turn this into a warning at least for the "i = j" case.
>
>But any thing else would just be a violation of the C and C++ standards.
>If you want a feature like this, it would be better if you get the C and
>C++ standards to change (which I really doubt they will).
>
>-- Pinski
Peter Lupton
pl@nch.com.au
NCH Swift Sound
Unit 13, Level 3
28 University Avenue
GPO Box 1169
Canberra ACT 2601
Australia
www.nch.com.au
More information about the Gcc
mailing list