Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 12.6 and functions taking/returning Boolean values.
#1
The second part of Rule 12.6 says that:
"Expressions that are effectively Boolean should not be used as operands to operators other than ..."
The list of the allowed operators has been corrected in TC1 to include &&, ||, !, =, ==, != and ?:

What about the function call operator () ?

If a Boolean value (by enforcement or by construction) is used as an argument to a function having a parameter whose type is Boolean (by enforcement), are we violating Rule 12.6? For instance:
Code:
typedef /* Boolean-by-enforcement type */ bool_t;
void foo(bool_t b);

void bar(int32_t a, int32_t b) {
  bool_t b = (a == b);
  foo(b); /* Non-compliant? */
}

A similar conversion problem exists when returning a Boolean value. In this case Rule 12.6 never applies (even though a Boolean value is being "abused") merely because, strictly speaking, the return statement is not an operator. For instance:
Code:
int32_t bar(int32_t a, int32_t b) {
  bool_t b = (a == b);
  return b; /* Compliant? */
}

Are the two examples above matching what was really meant by Rule 12.6 and TC1?
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)