5.9 and static function or global variable

Moderators: misra-c, david ward

Post Reply
xiangke
Posts: 9
Joined: Tue Apr 11, 2017 7:34 am
Company: valeo

5.9 and static function or global variable

Post by xiangke » Mon Jun 12, 2017 8:18 am

As we know, static function or global variable has only internal linkage, is invisible for other module,
Why their name can not be defined as same as ones in other translation unit?
For example, below case :
/*tunit1.c*/
static int8_t count;
static void foo ( void )
{
}

/*tunit2.c*/
static int8_t count;
static void foo ( void )
{
}

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

Re: 5.9 and static function or global variable

Post by misra-c » Thu Sep 21, 2017 10:36 am

The aim of the rule is to prevent any user confusion that might arise.

The user calling "foo" in tunit2.c might have forgotten that there is a function with that name defined in tunit2.c and assume that they are calling the function declared in tunit1.c, even though the other function is defined as "static".
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.5 Identifers”