I am looking at some legacy C code and got confused. It is something like:
UINT A, B = 1;
if((A = B) == 1) {
return(TRUE);
} else {
return(FALSE);
}
We all know there will be a compiler warning if we do if(A = B), but here it looks like the ‘if’ is checking A against 1. Am I correct?
First, it assigns the value of
BtoA(A = B), then it checks if the result of this assignment, which isAand evaluates to1, is equal to1.So technically you are correct: On the way it checks
Aagainst1.To make things easier to read, the code is equivalent to: