27-04-2006, 10:18 AM
Code:
uint32_t u_int_a;
uint32_t u_int_b;
u_int_a = -u_int_b;
This is a violation of rule 12.9 since the underlying type of u_int_b is unsigned.
----
Code:
int32_t int_a; /* changed from uint32_t */
uint32_t u_int_b;
int_a = -(int32_t)u_int_b; /* changed u_int_a to int_a */
This is allowed.
----
Code:
uint32_t u_int_a;
uint32_t u_int_b;
u_int_a = -(int32_t)u_int_b;
This is compliant with rule 12.9, but violates 10.1. because of the change of signedness on assignment.
Posted by and on behalf of the MISRA C Working Group