I’m using the Tasking VX toolset (built on Eclipse) and have a fairly basic but fundamental problem that I can’t get around… I’ve RTFMed and am still totally none the wiser.
Imagine the simple snippet of code:
#include <stdbool.h>
bool myFlag = false;
If I enable MISRA-C checking, I get the following:
MISRA-C rule 10.1 violation: [R] restrict the use of implicit conversions for integer types
Eclipse is set up as a C99 implementation, and as per the standard library definition, stdbool.h is defined as:
#define bool _Bool
#define true 1
#define false 0
I’m assuming that this error is because #define false 0 and the tool is implicitly converting to bool?
Note: if I cast the assignment, then the error is removed:
bool myFlag = (bool)false;
But (IMHO) that is masking the problem, not addressing it, and I really do not want to cast every assignment.
Tools such as LINT allow you to specify the bool type to stop these sort of false positives… I need the equivalent for Eclipse/Tasking
So my question is this:
I suspect that somewhere there is a tool option to tell TASKING that bool is the boolean type, and therefore false and true are OK to be used?
Is there?
{Please no discussions [on this thread] about the merits (or otherwise) of MISRA}
MISRA rule 10.1 says
is the same as:
0is of typeintwhich is a signed integer type but_Boolis an unsigned integer type.You are implicitly converting a value of a signed type to a value of an unsigned type and so
you are violating
a)in MISRA rule 10.1.Note that if you are using MISRA-C:2004 (I don’t think MISRA-C:2012 has been released), at the time of the publication only C90 was considered and
_Boolis a C99 addition. As I wrote in the comments you can get rid of the warning using a cast like this:This is the beauty of MISRA.