I have a struct:
struct TypeValue{
u8 type;
union{
u8 u8value;
s8 s8value;
}value;
}
Depending on type var we can have value from u8value
or s8value
.
Now I have a struct TypeValue
and I want to get the void pointer to the value
element (dont care pointer type), which one is correct:
void *ptr = &typevalue.value (1)
OR
void *ptr = &typevalue.value.u8value (2)
(put this in a for loop to find correct value depending on type)
Of course (2) is a correct way but I have to loop through the data type to get the correct pointer to correct value. But question is if (1) is correct as I am wondering if the pointer to the union is equal to the pointer to its element? Does big/little endian affect the result?