MISRA Discussion Forums

Full Version: Rule 10.1 violation with casting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

my MISRA checker generates a MISRA violation 10.1 (The signedness of an integer type is converted implicitly.(signed -> unsigned)), although a casting is done.

My C code:

1: #include
2: typedef unsigned char U8;
w: U8 WriteProtect = (U8) true;
x: if(WriteProtect == (U8) false) {
y: WriteProtect = (U8) true;
z: }

The MISRA checker identifies line x and y as a rule 10.1 violation. Why is this a rule 10.1 violation although a casting is done? Interestingly the MISRA checker identifies line w as OK. Have anybody an idea what is my fault?

Is it generally impossible in MISRA to assign a signed var to an unsigned var?
MISRA-C:2004 is based on C90, not C99 and therefore does not cover the use of the _Bool and the stdbool.h header file. However, let us assume for the purposes of this discussion that your MISRA checker is treating "true" and "false" as an integer.

Rule 10.1 concerns implicit conversions and is not violated by this example since casts are present. MISRA permits the use of a cast as used in this example.