Chris Green <chris@areti.co.uk> writes:
The problem is how to 'hand them around' between different parts of the code, if they're all globals it's easy to initialise them as well as create them in a file called, say, astime_config.c, this avoids the need to create them and *then* initialise them separately. However, apart from so many globals creating problems of its own, it then requires a 'extern' declaration for every value in a header file so that other source files can access the values.
It's relatively easy to avoid mentioning every global twice. For example: /* globals.h --------------------------------------------------------------- */ #if DEFINE_GLOBALS # define EXTERN # define INIT(x) =x #else # define EXTERN extern # define INIT(x) #endif EXTERN int foo INIT(3); EXTERN int bar INIT(99); /* globals.c --------------------------------------------------------------- */ #define DEFINE_GLOBALS 1 #include "globals.h" /* any other source file --------------------------------------------------- */ #include "globals.h" -- http://www.greenend.org.uk/rjk/