MISRA Discussion Forums

Full Version: Rule 3-9-1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:

T low_bits_mask(unsigned n);

T low_bits_mask(const unsigned n) {
return ~((~static_cast(0))
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.