Rule 5.5 and local static variables

6.5 Identifiers

Moderators: misra-c, david ward

Post Reply
pkruk
Posts: 20
Joined: Fri Jul 27, 2007 3:25 pm

Rule 5.5 and local static variables

Post by pkruk » Wed Nov 16, 2011 12:43 pm

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: Select all

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. ... =962#p1807 but I just wanted a clear confirmation.

Thanks

misra-c
Posts: 569
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 5.5 and local static variables

Post by misra-c » Thu Nov 17, 2011 8:11 pm

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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.5 Identifiers”