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
It is actually quite useful to have an operator that throws away the return value of an expression. You might be interested in the side effect of an expression, but not the return value.
Note that an expression may just as well be a call to a function.
However, in this case, many compilers would notice that a==b doesn't have a side effect (unless a bad C++ operator override is used) and warn about the meaningless construct.
The comma operator is extremely often used in the first and last part of a for statement:
for (a=1,b=2,c=3; a < c; a++, b=a-c) {}
where we only want side effects, but there are other uses too:
(t = a, a = b, b = t)
will swap a and b, and then return the new b value.
i get error in compile
Error compiling what code? What error?
What code?
What error?
Buggy forum?
When I looked at the thread, I could see all posts but my last from 9:03. I assume that I somehow forgot to press Post and write a new message. After I add the new message, I can see my 9:03 message...
Anyone else who have seen this problem?
"i get error in compile"
Yes, it frequently happens to me, too!