MISRA Discussion Forums
Rule 5.9 - Scope of uniqueness - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.5 Identifers (https://forum.misra.org.uk/forumdisplay.php?fid=160)
+---- Thread: Rule 5.9 - Scope of uniqueness (/showthread.php?tid=1203)



Rule 5.9 - Scope of uniqueness - jade - 11-09-2015

In Rule 5.9, the amplification says that the identifier name should be unique across all name spaces and translation units. This is an expansion of what's in the rule header, but is consistent with the purpose of the "Amplification" sections. However, the examples imply that identifiers can be unique if there is no linkage. Isn't this a contradiction?


Re: Rule 5.9 - Scope of uniqueness - Steve Montgomery - 14-09-2015

My interpretation is that an identifier with internal linkage must be different from any other identifier. However, an identifier with no linkage doesn't have to be unique provided that all uses of the identifier denote objects that also have no linkage.

So, in the examples given in the rule, the identifier index appears three times, twice in file1.c and once in file2.c. This is compliant with the rule because none of the objects has linkage. However, count in file1.c breaks the rule because it denotes an object with internal linkage and two objects with no linkage.


Re: Rule 5.9 - Scope of uniqueness - misra-c - 09-10-2015

The amplification clarifies the scopes over which identifiers with internal linkage should be checked. This rule only applies where one of the identifiers in the comparison has internal linkage.

The following table gives the application of rules for different combinations of object identifiers:
Code:
Identifier 2 linkage
   Identifier 1    |  external   | internal  | none
   ------------------------------------------------------------
   external        | 5.8         | 5.8 / 5.9 | 5.8
   -------------------------------------------------------------
   internal        | 5.8 / 5.9   | 5.9       | 5.9
   ------------------------------------------------------------
   none            | 5.8         | 5.9       | 5.3(if hidden)
   -------------------------------------------------------------