I ran across this code, where they are trying to convert from float to int
int val[5];
union {
int i;
float f;
} conv;
...
val is updated with some value
...
case OUT_FORMAT_FLOAT:
for (i = 0; i < count; i++) {
conv.f = val[i];
val[i] = conv.i;
}
But I am just not able to understand how this would work. The val[i]
is assigned to conv.f
and then the conv.i
is used store back the value into val[i]
. conv
is a union type since we are using f
, i
will not have a valid value right?
Am I missing something here?