M
moogyd
Hi,
I have debugged and fixed some code, but don't really understand the
behavior I have seen.
The following code compiles and runs with noo warnings (gcc 4.3.2 with
-Wall and -pendantic)
#include <stdio.h>
int main() {
int mask = 0x01 ;
int x = 0x80 ;
if (!(mask & x) == mask) {
printf("Match\n") ;
}
return 0 ;
}
When I run, it prints "Match" which I don't understand
My logic (note I am not a C programmer)
(mask & x) Evaluates to 0
!(mask & x) Evaluates to not 0. i.e. A positive number (I assumed
0x01)
So, the results of
!(mask & x) == mask *should* be false (but it obviously isn't :-(
My initial assumption was that the compiler was casting everything to
a common type (bool) due to the parenthesis on (mask & x). However, in
this case, I was hoping the gcc would warn me.
So, can anyone provide any clarification, or confirm my assumptions.
Thanks,
Steven
I have debugged and fixed some code, but don't really understand the
behavior I have seen.
The following code compiles and runs with noo warnings (gcc 4.3.2 with
-Wall and -pendantic)
#include <stdio.h>
int main() {
int mask = 0x01 ;
int x = 0x80 ;
if (!(mask & x) == mask) {
printf("Match\n") ;
}
return 0 ;
}
When I run, it prints "Match" which I don't understand
My logic (note I am not a C programmer)
(mask & x) Evaluates to 0
!(mask & x) Evaluates to not 0. i.e. A positive number (I assumed
0x01)
So, the results of
!(mask & x) == mask *should* be false (but it obviously isn't :-(
My initial assumption was that the compiler was casting everything to
a common type (bool) due to the parenthesis on (mask & x). However, in
this case, I was hoping the gcc would warn me.
So, can anyone provide any clarification, or confirm my assumptions.
Thanks,
Steven