Although your x
is of type long int
, the 1
is not. 1
is an int
, so 1<<63
is indeed undefined.
Try (static_cast<long int>(1) << 63)
, or 1L << 63
as suggested by Wojtek.
More Related Contents:
- Invalid solution for code challenge with operator restrictions
- Why doesn’t left bit-shift, “
- Why does left shift operation invoke Undefined Behaviour when the left side operand has negative value?
- Is multiplication and division using shift operators in C actually faster?
- Weird behavior of right shift operator (1 >> 32)
- Why was 1
- Arithmetic right shift gives bogus result?
- Is left and right shifting negative integers defined behavior?
- Is a logical right shift by a power of 2 faster in AVR?
- Right shift and signed integer
- C++ Looping / Array
- Is there a way to create a c++ gui game without win32 api, openGL, direct X and stuff? [closed]
- Why is sizeof giving incorrect number of bytes in C++?
- Where to use empty character constant ” in C++? [closed]
- Changing the object a pointer points to in c++
- What is wrong with using goto? [duplicate]
- Address of an array
- Does std::string have a null terminator?
- Difference between std::regex_match & std::regex_search?
- C++ unordered_set of vectors
- Mesh class called with default constructor not working OpenGL C++
- Do these members have unspecified ordering?
- Check traits for all variadic template arguments
- C++ Return value, reference, const reference
- Advantage of using trailing return type in C++11 functions
- How to effectively kill a process in C++ (Win32)?
- array of pointers as function parameter
- Set local environment variables in C++
- How to set, clear, and toggle a single bit?
- Why is pow(int, int) so slow?