Is it safe to assume that sizeof(double)
will always be greater than or equal to sizeof(void*)
?
To put this in some context, is the following portable?
int x = 100;
double tmp;
union {
double dbl;
void* ptr;
} conv;
conv.ptr = (void*)&x;
tmp = conv.dbl;
conv.dbl = tmp;
printf("%d\n", *((int*)conv.ptr));
It does work on the few machines that I've tested it on, but I can see this going horribly wrong if sizeof(void*) > sizeof(double)
.