fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..
What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;
Thanks,
Cric
There's nothing potentially wrong with it. Some may tell you that the
behavior is undefined according to 4.1 of the Standard. But 4.1 applies
only to lvalue to rvalue conversions of which none are present in this
example. Also, the C language Standard is even more clear than the C++
standard, but both agree that value's initial value is indeterminate,
not undefined.
So in this example, value's value is indeterminate before the bitwise
and, and its value is unchanged afterwards - assuming ints are
four-byte in size, of course.
Greg