Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
12.6 boolean expression assigned to int example
#1
Code:
uint16_t mc2_1206_x;
   uint16_t mc2_1206_y;
   uint16_t mc2_1206_z;
   mc2_1206_x = ( mc2_1206_y == mc2_1206_z ); /* Not compliant - mc2_1206_x is not effectively boolean */

This code has been marked as violation of rule 12.6 but I fail to see why. There are no (&&, || and !) operators so the first part of the rule does not apply. The boolean expression is used as operand of "=" so the second part of the rule is complied to as well.
Please correct me if I'm wrong.
Reply
#2
One of the models used to establish effectively boolean in MISRA-C:2004 requires consistent use of a variable's type.

Line 41:
Code:
mc2_1206_x = get_uint16 ( );

This first use of variable mc2_1206_x establishes this to be an integer type. Therefore the boolean assignment on line 76 is inconsistent with line 41. However, this is not explicitly covered in the modified rule text (TC1).

This is an advisory rule.

Tools may or may not flag this as compliant depending on the model of boolean type used. Consistent use of a single model of "boolean" is preferred in your project.

With the introduction of a boolean type in C99, the next version of MISRA-C will use this boolean type model.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)