Examples for 12.9 - unary minus operator - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.12 Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=39) +---- Thread: Examples for 12.9 - unary minus operator (/showthread.php?tid=243) |
Examples for 12.9 - unary minus operator - Manni - 24-04-2006 Hi Question about Rule 12.9: The unary minus operator shall not be applied to an expression whose underlying type is unsigned. Code: uint32_t u_int_a; 2. Shows this example, what the rule 12.9 mean? 4. Is this correct? (a = int) Code: uint32_t int_a; 5. Is this correct, too? (a = uint) Code: uint32_t u_int_a; 7. Have somebody good examples for rule breaks? And how to solve it? best regards, Manni - misra-c - 27-04-2006 Code: uint32_t u_int_a; 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 */ This is allowed. ---- Code: uint32_t u_int_a; This is compliant with rule 12.9, but violates 10.1. because of the change of signedness on assignment. |