Do I need to cast to unsigned char before calling toupper(), tolower(), et al.?

Yes, the argument to toupper needs to be converted to unsigned char to avoid the risk of undefined behavior. The types char, signed char, and unsigned char are three distinct types. char has the same range and representation as either signed char or unsigned char. (Plain char is very commonly signed and able to represent … Read more

Optimizing away a “while(1);” in C++0x

To me, the relevant justification is: This is intended to allow compiler transfor- mations, such as removal of empty loops, even when termination cannot be proven. Presumably, this is because proving termination mechanically is difficult, and the inability to prove termination hampers compilers which could otherwise make useful transformations, such as moving nondependent operations from … Read more

A positive lambda: ‘+[]{}’ – What sorcery is this? [duplicate]

Yes, the code is standard conforming. The + triggers a conversion to a plain old function pointer for the lambda. What happens is this: The compiler sees the first lambda ([]{}) and generates a closure object according to §5.1.2. As the lambda is a non-capturing lambda, the following applies: 5.1.2 Lambda expressions [expr.prim.lambda] 6 The … Read more

Order of evaluation of arguments using std::cout

The answer to this question changed in C++17. Evaluation of overloaded operators are now sequenced in the same way as for built-in operators (C++17 [over.match.oper]/2). Furthermore, the <<, >> and subscripting operators now have the left operand sequenced before the right, and the postfix-expression of a function call is sequenced before evaluation of the arguments. … Read more