Regis St-Gelais wrote:
> I usualy use a header to declare the global variables and I include that
> header in the main source file.
> Example:
> File: "MyGlobals.h"
> with inside it: Int16 gintAGlobalVariable;
>
> And I use another header to declare the externals and I include it in all
> the other source files:
> Example
> File: "MyExternalGlobals.h"
> With inside it: extern Int16 gintAGlobalVariable;
>
> The global declaration allocate the physical space for the variable.
> The extern declaration tells the compiler that the variable existe and was
> allocated some where else.
Wouldn't it be clearer and less error-prone to just create
MyGlobals.h with
extern Int16 gintAGlobalVariable;
and MyGlobals.c with
Int16 gintAGlobalVariable;
Then just compile MyGlobals.c and link with it instead of including
the variable declarations in some other source file?
Otherwise, you need to have a rule that MyGlobals.h can only be
included in one .c file. (If you include it in multiple ones,
you will have multiple instances of each global variable, and
the linker will choke because of duplicate symbols.) Following
the include-only-one-time rule will be necessary to build the
project and make it work, but it won't be clear to someone looking
at the project who doesn't know the "secret". Whereas everyone
(hopefully) understands what to do with regular .h and .c files.
On the other hand, I wonder if there can be some kind of advantage
of having them in the same compilation unit that the optimizer or
something can take advantage of...
- Logan
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/