Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's the whole point. =] This is a surprising aspect of C++: the shift expression doesn't have the type of the declared variable.

The integer literals we are shifting are of 'int' type, and the shift occurs at that type (based on the usual arithmetic conversions). There is stack overflow question with explanations and a good blog post here about it:

http://stackoverflow.com/questions/836544/usual-arithmetic-c...

http://blogs.msdn.com/b/oldnewthing/archive/2004/03/10/87247...

Also, you can look through the C++98 standard to understand all the details. Relevant sections are [expr]p9 and [expr.shift].



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: