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


> 
> 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


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