MISRA Discussion Forums
Rule 5.8: identifiers of interest - 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.8: identifiers of interest (/showthread.php?tid=1505)



Rule 5.8: identifiers of interest - sca2012 - 03-09-2019

The main goal of rule 5.8 (as well as 5.9), judging from the examples and amplifications, is to ensure that identifiers referring to objects or functions are not confused with the same identifiers that refer to different objects or functions.

How about identifiers that are reused by do not refer to neither objects nor functions?

For instance, a struct member:

Code:
int i;

struct S {
    int i;    // identifier is reused but cannot actually be confused with the object i at line 1
};
Is this scenario still a violation to the rule?


Re: Rule 5.8: identifiers of interest - misra-c - 11-10-2019

The Amplification for rule 5.8 states
"An identifier used as an external identifier shall not be used for any other purpose in any name space or translation unit, even if it denotes an object with no linkage."

Appendix J of the MISRA C:2012 guidelines defines an external identifier as an "identifier with external linkage". In your example "int i" is assumed to be at file scope level and is therefore an external identifier. Therefore your example is a violation of rule 5.8.