c++,memory,integer,signed,signed-integer

With the help of a lot of the posts above, I've come up with this solution: inline void reduceSignedIntWidth(int32_t& destInt, int width) { //create a value mask, with 1's at the masked part uint32_t l_mask = (0x01u << width) - 1; destInt &= l_mask; } It will return the reduced...

c++,segmentation-fault,sdl-2,signed-integer

First of all, bools don't default to anything in C++, you need to initialize them. The fact that they appear to always be true is that they're byte in size. Which means they have a size between 0 and 255 inclusive. Only 0 would mean false so its a 255...

c++,c++11,language-lawyer,unsigned-integer,signed-integer

size_t r = 0; r--; const bool result = (r == -1); Strictly speaking, the value of result is implementation-defined. In practice, it's almost certain to be true; I'd be surprised if there were an implementation where it's false. The value of r after r-- is the value of SIZE_MAX,...

c++,bitwise-operators,unsigned-integer,integer-promotion,signed-integer

[expr.unary.op] The operand of ~ shall have integral or unscoped enumeration type; the result is the one’s complement of its operand. Integral promotions are performed. [expr.shift] The shift operators << and >> group left-to-right. [...] The operands shall be of integral or unscoped enumeration type and integral promotions are performed. What's...