In my firm project, the AUTOSAR platform defines booleans like this
typedef unsigned char boolean;
plus
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
This is not modifiable. Then we get the MISRA 10.3 error Expression assigned to a narrower or different essential type [MISRA 2012 Rule 10.3, required] on the following two assignments (real code replaced, of course!)
boolean mybool = (boolean)FALSE;
if(some_condition)
{
mybool = (boolean)TRUE;
}
We've tried other convertions with (uint8)FALSE
or (unsigned char)FALSE
or even without a convertion mybool = TRUE;
without curing the issue. We would be happy to avoid justifying for deviation.
Does anyone has an idea of what happens and how to cure it?
@Fredrik Thanks for your first answer. I put this in a dummy header, included it in the 'culprit' .c
and run PC-Lint/MISRA on this unit
#define testTRUE 1U
boolean x = testTRUE;
boolean y = (uint8)testTRUE;
boolean z = (boolean)testTRUE;
#define testTRUE_2 1
boolean x_2 = testTRUE_2;
boolean y_2 = (uint8)testTRUE_2;
boolean z_2 = (boolean)testTRUE_2;
unsigned char x_3 = (boolean)1;
unsigned char y_3 = (boolean)testTRUE;
unsigned char z_3 = (boolean)testTRUE_2;
and get the same issue on the first 6 assignments. As to last 3 assignments, the error is not raised but perhaps hidden by this one in replacement: Use of modifier or type 'unsigned' outside of a typedef [MISRA 2012 Directive 4.6, advisory]