Paavo Helde said:
Even if this was true, who should know better about the sizes of ints and
numbers of bits than the compiler doing the compilation? And thanks, I do
not want warnings about my code not being portable to some hypothetical
platform with 16-bit ints or 9-bit bytes (I would use other code branches
or typedefs for them if I really need to support such).
I don't see how the behavior of the example code being discussed would
depend on the amount of bits in a char on an int. If you take a value of
type char and calculate a bitwise-and with an int literal, you will get
an exact set of possible results, and this does not depend on the bit
sizes of anything. (Even in the hypothetical case that the amount of bits
in an int would be smaller than the int literal used in the code, you
would *still* not get a result which would fall outside of the listed
cases.)
I have, in fact, seen some people sometimes having very odd
misconceptions about C (and hence C++), with regards to bit manipulation.
For example, I once saw an open-source program where bit-shifting was
avoided (in a situation where you would normally use it) because the
programmer thought that its result depends on the endianess of the
target architecture, and hence bit-shifting is not portable (this was
stated in the code comments).