Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Underlying type of unary minus operator (-var)
#1
I have a question about underlying type of expressions involving unary minus operator. This is connected to 10.1 rule that disallows signed/unsigned conversions.

For example:
Code:
uint8_t  mc2_1209_u8a;
mc2_1209_u8a = -mc2_1209_u8a;

What is the underlying type of "-mc2_1209_u8a" expression? If it is unsigned then rule 10.1 is not violated; if it is signed then the rule is violated. (Of course this code is a violation of rule 12.9 anyway).

In my opinion the underlying type is still uint8 because C standard says in 6.5.3.3[3] (C99 cited):
Quote:The result of the unary - operator is the negative of its (promoted) operand.
The integer promotions are performed on the operand, and the result has the
promoted type.

This seems consistent with rule 12.9 which disallows using unary minus operator on unsigned operands.

Please correct me if I am wrong or if this was not the intention of MISRA rules.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)