07-01-2010, 05:40 PM
Lundin Wrote:Integer constants can never be unsigned char or unsigned short.In the C standard, yes constants can never be char or short. However, a constants fundamental type can char or short if that is the smallest type that is capable of representing its value.
Lundin Wrote:And yes, by rule 10.5 you must immediately cast the result into this operand in case uint16_t happens to be unsigned short. In that case, the integer promotions will jump in and possibly change signedness of the final expression. Again, this depends on "integer conversion rank" in the C standard, and not on the implemented size of unsigned short.If unsigned short and unsigned int are the same size, how will the signedness of the final expression change? The unsigned short will be promoted to unsigned int because int cannot represent the entire range of values representable by unsigned short. Besides, this rule is only concerned with higher order bits showing up when the user didn't expect it, and this won't happen if short and int are the same size.
By your rationale, you are inferring, from rule 10.5, that all objects of user defined types should be immediately cast just in case they are smaller than an int. It is perfectly legal to have a uint32_t be an unsigned short. If that is the intention, then the rule should be something like "always cast every result of the ~ and
<t></t>