c++,c,int,short,integer-promotion

If we look at the Rationale for International Standard—Programming Languages—C in section 6.3.1.8 Usual arithmetic conversions it says (emphasis mine going forward): The rules in the Standard for these conversions are slight modifications of those in K&R: the modifications accommodate the added types and the value preserving rules. Explicit license...

c,unary-operator,integer-promotion,binary-operators

Usually, yes, unless on your platform uint32_t would be a narrow type. Then it would first be promoted to int and the negation would be made in that type.

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...

c++,static-cast,unary-operator,integer-promotion

IMO, there is one important advantage of using static_cast, even if it is a little bit more verbose: it allows you to quickly search your code for casts via grep or any other text searching utility. In large projects this may make the difference, since otherwise C-style casts are often...

They're the same because they're all different representations of -1. They print as 32 bits' worth of ff becaue you're on a 32-bit machine and you used %d and the default argument promotions took place (basically, everything smaller gets promoted to int). Try using %hx. (That'll probably get you ffff;...

No. The usual arithmetic conversions involve integral promotion under certain circumstances, but these are two separate mechanisms: [C++14: 5/10]: Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is...

c++,c,types,casting,integer-promotion

A short cannot be longer than an int but on some platforms it may be the same size. The same goes for int and long. This means that if the "smaller" one is unsigned, the "larger" one must be too.

c,unsigned,short,integer-promotion

When firstIndex is unsigned int, in i >= firstIndex then i is converted to unsigned int because of the usual arithmetic conversions. So if i is negative it becomes a large integer in the comparison expression. When firstIndex is unsigned short int in i >= firstIndex, firstIndex is promoted to...

According to the C++ Standard 10 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic...

c++,c++11,auto,integer-promotion

Addition will perform the usual arithmetic conversions on its operands which in this case will result in the operands being promoted to int due the the integer promotions and the result will also be int. You can use uint16_t instead of auto to force a conversion back or in the...