Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.1 violation with casting
#1
Hello,

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?
<t></t>
Reply
#2
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.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)