global static vars problem

Hi all,

I'm trying to put a few function pointers in a header file so that I can use those function pointers as any other function by including the header file. The first problem was that than of-course you get linking errors because everywhere you include that header file you create a new definition of a global variable. So I gave the function pointers a static variable and it seemed to compile fine, my problem now however is that after I assign the appropriate functions (loaded from a dll file) to those pointers in one function, they don't seem to have changed for another function.
I'm bedazzled! Anyone has an idea?

Thank you!
Two popular methods are to use the preprocessor commands:
#pragma once
or
1
2
3
4
5
6
#ifndef  _SOME_NAME_NO_ONE_ELSE_WILL_USE
#define _SOME_NAME_NO_ONE_ELSE_WILL_USE

/*Code Code Code*/

#endif 


EDIT: Sorry I forgot part of the "#ifndef" I'm a little off today.
Last edited on
Also, can't you declare the variables as extern in the header file and then initialize them in one particular source file?
I can't use definitions because the pointers need to be get- and set-able.

I'll try to make them extern like you said, I don't exactly what it means yet because I never had to deal with it, but I know it is something like showing the compiler it defined outside it's source, or something. :P

The pointers don't need to be initialized to a specific value, once I assign them a value, they will be either 0 or a valid pointer.
Computergeek01, I know what you mean but that's not my problem. Try to create a header (with preprocessor protection of-course) with a few global variables and include them in a few source files and see what happens.
There's also "dllexport" and "dllimport" function attributes but those I understand are compiler specific.
we'll, i'm using a function to load the functions (wglGetProcAddress).

But I made the pointers extern and initialized them in a source file, the work now as desired, thank you!
static variables in the global scope make them local to the file they are in. This is also a deprecated construct anyway, you should use unnamed namespaces if you want that effect.

But anyway, as you found out, you need to extern them and define them wherever.
Topic archived. No new replies allowed.