This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

if condition

Hello,
I was compiling my firmware program written in
C using Keil microVision2 V2.4 compiler.
The target is c8051F120 microcontroller.

I noticed that the compiler accepted the following:
if (A == B, 1) {;}

Does anyone know why? I would think that a syntatically error is committed here.

Thanks in advance.

HL

Parents
  • Does anyone know why?

    Yes !

    Because it's perfectly valid C.

    Comma is the "sequential evaluation operator" in C. It allows several expressions in places where only one of them would be expected (e.g. in an if, for, while or similar). The value of the sequential evaluation operator is equal to that of the right-most expression, in your case, "1".

Reply
  • Does anyone know why?

    Yes !

    Because it's perfectly valid C.

    Comma is the "sequential evaluation operator" in C. It allows several expressions in places where only one of them would be expected (e.g. in an if, for, while or similar). The value of the sequential evaluation operator is equal to that of the right-most expression, in your case, "1".

Children
No data