Tell the linker they exist elsewhere...
globals.h
Code:
#ifndef INCLUDED_GLOBALS_H
#define INCLUDED_GLOBALS_H
extern int myVar;
#endif /* INCLUDED_GLOBALS_H */
main.c
Code:
#include "globals.h"
#include "something.h"
int myVar = 10;
int main(void)
{
printf("myVar = %d\n", myVar);
something_whatever();
printf("myVar = %d\n", myVar);
return 0;
}
something.c
Code:
#include "globals.h"
void something_whatever(void)
{
myVar = 50;
}
You could also add set/fetch methods in main.c and call them from something.c (that way you can control how and who can set it). Otherwise it's a tad "dangerous"