Rule 3-9-1 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132) +---- Thread: Rule 3-9-1 (/showthread.php?tid=870) |
Rule 3-9-1 - pmhill - 30-12-2011 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)) Re: Rule 3-9-1 - misra cpp - 05-10-2015 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. |