We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
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".