No, no, no! That is
not how you do modular programming in C!
You don't use global variables at all in modular programming, they are considered very poor programming, and so is the "extern" keyword when used for variables. Also, there is never a reason to use global variables in the C language.
This is how you write a code module properly in C:
/* h file for "module" */
#ifndef MODULE_H /* this is called header guards and they prevent linking errors */
#define MODULE_H
void some_function (void);
void set_x (int x);
int get_x (void);
#endif /* MODULE_H */
(The C purist would even write function prototypes as
extern void some_function (void);
but that is an advanced topic - the meaning is the same.)
/* c file for "module" */
#include "module.h"
static int _x;
/* A private variable. The "_" syntax is commonly used for private variables or functions. The static keyword guarantees that the variable can't be accessed from outside of the module, neither accidently nor with purpose. It can however be accessed through the whole code module. */
void some_function (void)
{
}
void set_x (int x)
{
_x = x;
}
int get_x (void)
{
return _x;
}
/* some c file using "module" */
#include "module.h"
int main()
{
int y;
set_x(123);
...
y = get_x() + something;
}