I have a function defined in a header-only library that looks like this:
inline bar **foo_ptr() {
static bar *value = NULL;
return &value;
}
This is my hackish way of initializing a global variable without defining it in a *.c file.
This compiles fine in VS2010 (after a #define inline __inline), but dies in an angry fit of multiple definition rage upon any attempt to compile it in MinGW. This is making me Very Sad.
AFAIK, I can't just use a static inline
function, as it would create multiple occurrences of value, which, for this situation, is a Very Bad Thing.
What keyword(s) should I really be using in order to make this work? Am I going at it completely wrong? Is there an alternative way to initialize a header-only global variable to NULL?
I would prefer to stay away from init methods.
Thanks :D