Dirk said:
Is there any way I can store all my globals in one file while making
them accessible to other modules? ...
The term "globals" is not defined in the standard. There are several
different meanings that people use. The loosest definition I've heard
is equivalent to "file scope object". A stricter definition (the one I
prefer) is "file scope object with external linkage". I'll use that
definition to interpret your question. If that's not what you meant,
let me know.
The strictest definition that I'm aware of anyone actually using is
something like "object whose identifier always refers to that object,
when used anywhere in the code", which means that the term does not
refer to any feature of C. That's because in C, you can always hide an
outer-scope declaration by declaring the same identifier with a
different meaning in an inner scope. As far as I can tell, the only
useful feature of this definition is that it allows that person to say
"C does not have globals", in flat contradiction to common usage.
Globals should generally be avoided, but can be appropriate on rare
occasions.
Yes, it's trivial to put all of your globals in the same file.
However, it's not a good idea. When globals are justified, they
generally belong in the same module as the code that is most directly
relevant to them. This is not needed in order to make that code work,
it's just a matter of good organization, which will make code
maintenance a lot easier. If you want to re-use a given module in a
different program, the globals associated with that module should go
along with the code that uses those globals, which is trivial to use
if they're already in that module.
... I know I can do an extern on each one
in the relevent module, but it rather defeats the whole purpose.
What is this "whole purpose" that is defeated by doing that, and how
is it defeated? Is it a sufficiently important purpose to justify
using an otherwise sub-optimal approach to program design?