On 11/08/05 13:07:10, Chris Green wrote:
However none of this addresses my question really. The issue is
trying
to avoid repeating what is essentially the same thing over and over again when you have a large number of loosely associated values (the clock configuration parameters).
If they're globals you have to both initialise them and declare them as extern. Every global is (at least) duplicated as:-
int xsize = 1234; // in a .c file somewhere
and
extern int xsize; // in a .h file somewhere
If (as there should be) there are very few globals this is OK, but with the 50 or more the clock requires it's messy. They *are* required in different places because they're modified by the command line parsing and used in the X code which are separate source files.
If you think globals are the best solution then you could adopt a code generation approach.
Create a file called globals.c or something similar and list the variables and their initialisers there, so in your above example:
int xsize = 1234;
Now use a script, perhaps in perl or similar, to process this file by taking each non-comment line, grabbing the part before the '=' sign (or before the final semicolon if there is no '=' on that line), prepend 'extern ' to it and write it out. The output of this script goes into globals.h or similar which can then be included by other modules.
This script can be run from a makefile to to add a new variable you edit globals.c and run make.
Steve.