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
"The comma operator, of course, has it's (sic) uses, but allowing it where "the result is discarded" is nothing but an obfusciation allowance."
The whole point of the comma operator is precisely that it allows you to discard the result of the left-hand operand!
The place where it can be useful is where the expression has side-effects...
As neither expression in the example given has side effects, would some compilers give a "Code with no effect" warning here?
...how did you come to write
if (A == B, 1) {;}
in the first place?
Was it just a typo?
"As neither expression in the example given has side effects, ..."
Without knowing what 'A' and 'B' are, we can't really say that. They could be macros.
yes, it was a typo. Did not even know it was a legitimate syntax in the first place.