-Wconversion warning while using operator <<= on unsigned char
问题 When I compile the following code with gcc : int main() { unsigned char c = 1; c <<= 1; // WARNING ON THIS LINE return 0; } I get this warning : conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion] Why ? What is wrong with this code ? Actually, can I really use the oprator <<= on a unsigned char variable ? Compilation command : g++ test.cpp -Wconversion -o test.exe 回答1: This is a valid warning: c <<= 1; is equivalent to: c = c << 1 and the rules for << say that the