: Hi,
: Suppose we have declared a static variable or function in one of the source files and now we wish to use same variable or function in other source file, how do we use this?
: _shantanuk.
:
You can't. The whole purpose of static variables is to block other files from using them.
You must do like this, which is also good programming practice:
/* myfile.h */
int getMyVar (void);
/* myfile.c */
#include "myfile.h"
static int myVar;
int getMyVar (void)
{
return myVar;
}
/* main.c */
#include "myfile.h"
int main()
{
printf("%d\n", getMyVar());
return 0;
}