My question is driven by the need to correctly pass a double
variable via a void *
function argument. I ask because on my machine sizeof(void *)
is 4
, and sizeof(double)
is 8
, casting one to the other seems like it should result in a problem, but my compiler (CLANG, with ALL warnings on.) gives no indication of a problem, and the code seems to work fine.
Note that I have seen this, and this. They have similar component words in their titles, but do not answer this specific question.
Would the following lead to a strict aliasing violation error?, or undefined behavior?
// some calling function
double a = 0.000234423;
func1(&a);
...
void func1(void *var)
{
double a = *(double *)(var);
}