In The Art of Multiprocessor Programming, p215, the authors say that in C, you could \"steal\" a bit from a pointer, and using bit-wise operators extract some flag (a mark)
Make sure the pointee objects are aligned in memory so that all your pointers are even numbers. The last bit is then free for storing a single boolean flag. (This cannot be done completely portably. so you need knowledge of the platform.)
Move the pointers around as integers of type uintptr_t. These can easily be manipulated:
bool get_flag(uintptr_t p)
{
return p & 1;
}
void *get_pointer(uintptr_t p)
{
return (void *)(p & (UINTPTR_MAX ^ 1));
}
uintptr_t set_flag(uintptr_t p, bool value)
{
return (p & (UINTPTR_MAX ^ 1)) | value;
}