Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 3-9-1
#1
The rule states that the types for a function declaration and definition must be token-for-token identical. How literally should this rule be taken. I have two cases where this rule seems to conflict with normal or good practice.

1. In a function definition, a 'const' qualifier is often included for parameters passed by value as a promise that the implementation will not modify these parameters. This qualifier cannot be included in the declaration. For example:

template
T low_bits_mask(unsigned n);

template
T low_bits_mask(const unsigned n) {
return ~((~static_cast(0))
<t></t>
Reply
#2
In the examples quoted, there are not two instances of the same function.

Rule 3-9-1 relates to the case where the same function is declared in two translation units and these two declarations must obey the 'One Definition Rule'.

Token-for-token compliance is the easiest way to ensure this.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)