On Mon, May 01, 2000 at 02:25:20PM -0400, Sam Charette wrote:
> I have a question for anyone who is willing to help me out in my time of
> utter confusion.
> 
> I am doing a proof of concept (ergo little time for design, and therefor
> not very well structured) for a project and am having problems with
> certain global variables.
> 
> In the main application header file I create global variables for each
> of the databases to be used by the application.  I use the:
> 
> #ifndef <identifier>
> #define <identifier>

I assume you put the declarations here :).

> #endif
> 
> group in order to include the contents of my header files only once
> regardless as to how often it is included by other files.  I must,
> however, for some reason declare my globals as static since if I don't I
> get multiple definition errors.

In C, calling something static causes it to be LOCAL to the module.
So each file you use will have its own copy of that variable.

> Now, I have 3 different files accessing these globals.  Two of them work
> fine, one does not.  When I get to that file the database variable being
> used seems to have been reset and so I get a rather nasty error when I
> try to access it with the DmNumRecords function.

No, local copy #2 probably has zero in, but you wrote to local copy #1.

Try declaring them all extern.

Some compilers create common memory regions out of globals so don't
create such conflicts (either plain or extern).

One kludge I use for annoying compilers is to use:

#ifndef MAIN
#define EXTERN extern
#else
#define EXTERN
#endif

EXTERN int globalvar;

And define MAIN only in one of the .c files.

> I really don't understand why the linker thinks there are multiple
> declarations of these variables if not set static, and I do not
> understand why two of the files would work and one would not.  They all
> have the proper headers included...

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to