"ravinder thakur" <th*************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
i have
encounterd a where i have a static and a global variable with the same
name. now what rules c languages uses to reslolve the ambiguity between
these two variables with the same names. more specifically what will
happen if the both of these varaibles gets included in some compilation
unit due to the interdependency between the header files???
If you don't tell anything about the global variable to the unit with the
static variable, there will be no problem. Otherwise, if the unit *sees*
that global variable (through inclusion of something with "extern type
globalVariable;"), then the compiler must issue at least a warning if not
error. If it doesn't, there's a problem...
The simplest solution is to rename one of the variables, most probably the
static one as this change would affect just one compilation unit, whereas
renaming the global variable will introduce changes in all its users.
However, if there's a local variable and a static/global variable having the
same name, this would be OK and the local one will be given favor and used.
Alex