21-01-2011, 06:19 PM
@misra-c:
Thank you for the explanation. I wanted to confirm that what I'm doing is both OK with respect to the intent of MISRA, yet also technically a violation the way the rules are currently written. You've confirmed both of those. And I agree that justifying the Rule 10.1 deviation should be no problem.
The issue now becomes more one of telling the rule checker to ignore these assignments. I need a way to prevent the rule checker from reporting these violations, without turning off Rule 10.1 altogether, and without peppering the code with special commands to tell the rule checker that each of the assignments is OK. I think once the rules are updated as you mention, and then once rule checkers are updated accordingly, this becomes a non-issue. But in the mean-time, I've got to deal with it.
I can think of two mechanisms:
or
I actually think I like the first mechanism, because I can eventually (once MISRA and the rule checker support it) simply search for and remove the ISTRUE macro. If I use the (TBool) cast, then I've basically got a redundant cast, and down the road I can't just "blindly" remove all (TBool) casts, because some may be legitimate.
Also, I can conditionally define the ISTRUE macro to be something like
so that my rule checker is happy, but the macro is transparent to the compiler.
Thank you for the explanation. I wanted to confirm that what I'm doing is both OK with respect to the intent of MISRA, yet also technically a violation the way the rules are currently written. You've confirmed both of those. And I agree that justifying the Rule 10.1 deviation should be no problem.
The issue now becomes more one of telling the rule checker to ignore these assignments. I need a way to prevent the rule checker from reporting these violations, without turning off Rule 10.1 altogether, and without peppering the code with special commands to tell the rule checker that each of the assignments is OK. I think once the rules are updated as you mention, and then once rule checkers are updated accordingly, this becomes a non-issue. But in the mean-time, I've got to deal with it.
I can think of two mechanisms:
Code:
unsignedBoolFlag = ISTRUE(c > d);
Code:
unsignedBoolFlag = (TBool)(c > d);
Also, I can conditionally define the ISTRUE macro to be something like
Code:
#ifdef RULE_CHECKING
#define ISTRUE(cond) ((cond) ? TRUE : FALSE)
#else
#define ISTRUE(cond) (cond)
#endif
<t></t>