MISRA Discussion Forums
5.9 and static function or global variable - 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: 5.9 and static function or global variable (/showthread.php?tid=1347)



5.9 and static function or global variable - xiangke - 12-06-2017

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 )
{
}


Re: 5.9 and static function or global variable - misra-c - 21-09-2017

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".