I do know that ~0 will evaluate the maximum word sized bit 1s (and thus takes caring of portability), but I am still not getting why ((1 << N) – 1) is discouraged?
Please share if you used the second form and got into any trouble.
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.
Look at these lines:
Line
1compiles and behaves like expected.Line
2gives the warning integer overflow in expression.This is because
1 << 31is treated by default as a signed int, so1 << 31 = -2147483648, which is the smallest possible integer.As a result, resting
1causes an overflow.