Fanie said:
Since the "extern" precedes the definition, it simply declares the array so
that other functions know what to make of it during compilation.
The actual definition takes place when the "extern" is omitted and this may
be done anywhere in the code, and the size is only needed during linking
time.
Unlike common misconception, the difinition may take place in either the
header or implementation file, however, if in the header (depending on the
size and structure of your file) it may defined more than once if the header
is imported more that once which will result in a compile error.
I personally prefer to place the variable definitions of all global
variables in the header files, since this simplifies maintanance, but you
have to construct your headers carefully.
That's generally considered "A Bad Thing (c)". Headers should
declare things, objects and values, text substitutions, etc. The
header should never cause the creation of any object or function.
Personal preferences aside, headers allow translation units
(modules) to share certain information common to all of them.
If you take care not to define objects, you can use the same header
for all the modules.
As soon as the header defines something, it can only be used once.
That means each of your .c modules will require a different header.
If a .c module cannot share headers with its siblings, constructed
carefully or not, why have a header at all?
Please explain 'simplifies maintenance' in this context.