Context:
I have a chunk of memory that's shared between two processes via shm_open
. I am guaranteed that after ftruncate
ing and mmap
ing it, the whole chunk has the bit pattern 00000...
. I need to share a boolean value across the two processes.
A more concrete question:
Is the following guaranteed to be okay (the assertion doesn't fail and UB does not occur) on reasonable POSIX systems?
void *my_shared_memory_region = calloc(1024, 1);
bool *my_bool = reinterpret_cast<bool*>(my_shared_memory_region);
assert(*my_bool == false);
I believe that there are some restrictions on the actual values that can live inside of a bool
, so I'm not sure. I think this question is distinct from this one because reinterpret_cast
doesn't do the same kind of conversions that C-style casts do.