MISRA Discussion Forums
Rule 5.5 and local static variables - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.5 Identifiers (https://forum.misra.org.uk/forumdisplay.php?fid=32)
+---- Thread: Rule 5.5 and local static variables (/showthread.php?tid=865)



Rule 5.5 and local static variables - pkruk - 16-11-2011

Hello,

I wanted to confirm if having local static variables with the same name in different functions is not compliant with rule 5.5.
For example:

Code:
void foo1() {
    static int x1 = 0; /* Not compliant - foo1, foo2 */
    static int x2 = 0; /* Not compliant - foo1, foo2 */
}
void foo2() {
    static int x1 = 0; /* Not compilant - foo1, foo2 */
    int x2;            /* Not compliant - foo1, foo2 */
    int x3;            /* Not compliant - global, foo2 */
}
extern int x3; /* Not compliant - global, foo2 */

This is similar to http://www.misra-c.com/forum/viewtopic.php?f=61&t=812 and http://www.misra-c.com/forum/viewtopic.php?f=61&t=962#p1807 but I just wanted a clear confirmation.

Thanks


Re: Rule 5.5 and local static variables - misra-c - 17-11-2011

The examples are all correctly identified as being non-compliant.

Rule 5.5 applies to all scopes. Any identifier used to declare or define an object with static storage duration, regardless of its scope, shall not be used to declare or define any other object, regardless of its storage duration or scope.