M
moogyd
Experts,
I have written (and delivered :-( ) some code. I wanted to check that
the bottom two bits of P8 were set, and so I produced:
if (P8 & (uint8)0x03 == (uint8)0x03) {
// Code
}
There is a mistake in this code in that equality is higher precedence
than bitwise and. Therefore my code behaves as:
if (P8 & ((uint8)0x03 == (uint8)0x03)) {
// Code
}
0x03==0x03 always equates to TRUE. Therefore my code equates to
if (P8 & TRUE) {
// code
}
So my question is, how is TRUE likely to be represented, and when will
the code be run.
(I fully expect the answer to be "It depends on the compiler")
Thanks
Steven (who usually uses the strongly typed VHDL)
I have written (and delivered :-( ) some code. I wanted to check that
the bottom two bits of P8 were set, and so I produced:
if (P8 & (uint8)0x03 == (uint8)0x03) {
// Code
}
There is a mistake in this code in that equality is higher precedence
than bitwise and. Therefore my code behaves as:
if (P8 & ((uint8)0x03 == (uint8)0x03)) {
// Code
}
0x03==0x03 always equates to TRUE. Therefore my code equates to
if (P8 & TRUE) {
// code
}
So my question is, how is TRUE likely to be represented, and when will
the code be run.
(I fully expect the answer to be "It depends on the compiler")
Thanks
Steven (who usually uses the strongly typed VHDL)