Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.5 cast of enum to boolean
#1
Code:
#include

typedef enum{ NOT_OK, OK, MAYBE } assessment;

void foo (assessment a)
{
  bool result;
  result = (bool) NOT_OK;    /* [1] compliant with MISRA C:2012 Rule 10.5? */
  /*. . . */
  result = (bool) a;         /* [2] not compliant with MISRA C:2012 Rule 10.5? */
  /*. . . */
}
The exception to Rule 10.5 permits a cast of an integer constant expression with the value 0 or 1 to a type which is defined as essentially Boolean. However the rule does not permit the cast of objects with essentially enum type to an essentially Boolean type.

Am I correct to say that [1] is compliant with rule 10.5, but [2] is not compliant?
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)