[cfe-dev] why is such a code allowed?
James Molloy
james at jamesmolloy.co.uk
Fri Feb 6 08:51:20 PST 2015
Hi Guy,
C89 doesn't have the concept of "bool" - all comparisons return an int (or
is it an unsigned int?) in the range [0,1].
C99 and C++ build on C89 so even though they have the concept of "bool",
the type of a comparison was not changed.
Cheers,
James
[Even though this C-language question seems easy enough for me to answer, I
am certain that a true language lawyer will pipe up and tell me I'm wrong
;) ]
On Fri Feb 06 2015 at 4:37:11 PM Guy Maurel <guy.maurel at kde.org> wrote:
> Hello!
>
> Let say:
> int a = 5;
> int b = 7;
> int i = 20;
> if ((a == b) + i) {
> a = 15;
> }
> My question is:
> The expression (a == b) gives a bool result.
> Why is it allowed to add a "bool" and an "int".
>
> Thanks
> --
> Guy Maurel
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150206/7f9b83ec/attachment.html>
More information about the cfe-dev
mailing list