>>It has to work, because it's the same physical space in memory. <<
What he is saying is that technically this is not a legal assumption.
Technically he is right. However, you are unlikely to see a problem in this instance.
Here's some code to demonstrate:
Code:
#include <stdio.h>
#include <stddef.h>
int main(void) {
union unTest {
struct {
char a;
long b;
short c;
char d;
} stTest;
long long llTest;
} test;
printf("%d, %d, %d, %d, %d", sizeof(test), sizeof(test.stTest), sizeof(test.llTest),
offsetof(union unTest, stTest), offsetof(union unTest, llTest));
getchar();
return 0;
}
Code:
Results(MSVC): 16, 12, 8, 0, 0