question: shared global pointer
Hi to all,
This is more a design question. We have a low-level class that needs uses a
void* for its internal state; there are 3 possible cases, null pointer, a
global constant and anything else is assumed to be a malloc'ed pointer.
the global constant is returned by a static member function, and at first it
was:
class LowLevel
{
public:
static const void* BUSY()
{
static int BUSY_PLACEHOLDER = 0;
return &BUSY_PLACEHOLDER;
}
// ...
};
this had some good side effects, as BUSY() returns a "true pointer", which
is not malloc'ed; there is no concurrency problem and moreover VC2005 is
able to display BUSY_PLACEHOLDER aside of the pointer value, so that at
debug time we could easily knew what the pointer was.
unfortunately the class is now shared between an exe and a dll, so that
BUSY() would return two different pointers, so we (urgh!) reverted to a
constant:
static const void* BUSY()
{
return reinterpret_cast<const void*>(ptrdiff_t(1));
}
this works, since ptrdiff_t has the right length, and malloc won't return
0x000...01, but it's definitely ugly. Is there some other reasonable
solution for the problem?