Is the following undefined and why?
int i = 0xFF;
unsigned int r = i << 24;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The behaviour is technically undefined unless the
inttype has more than 32 bits.From C++11, 5.8/2 (describing an expression
E1 << E2):The result type of
i << 24is (signed)int; if that has 32 bits or less, then0xff * 2^24 == 0xff000000is not representable (the maximum representable 32-bit signed value being0x7fffffff), so behaviour is undefined as specified in that clause.