How safe is reading a void * pointing to a char as an int?
Example: To test the first bit of a char in a system where 8 bit chars are much slower to access than 32 bit ints.
char c = 'B'; // a char here to illustrate the potentially dangerous case, but the
// point is this could be a char, could be an int... I am just
// interested in the first bit
void *v = &c;
int i = *(int *)v;
if (i & 0x01)
{
printf("yep");
}
Seems to work, but if my char (c) was right at the edge of the valid memory allocated to this process, would it be reading into invalid memory? Or is the system clever enough to stop copying after the first 8 bits?
thanks