Say we have the following code:
typedef union {
float e[4];
__v4sf v;
float *s;
} __vec4f;
float test[12];
int main(){
__vec4f one;
printf("adrs: &one.s = 0x%x, &one.e = 0x%x\n", &one.s, &one.e);
printf("vals: one.s = 0x%x, one.e = 0x%x\n",one.s,one.e);
one.s = test;
printf("adrs: &one.s = 0x%x, &one.e = 0x%x\n", &one.s, &one.e);
printf("vals: one.s = 0x%x, one.e = 0x%x\n",one.s,one.e);
return 0;
}
When running the results are like follows:
adrs: &one.s = 0xbffff270, &one.e = 0xbffff270
vals: one.s = 0x927ff590, one.e = 0xbffff270
adrs: &one.s = 0xbffff270, &one.e = 0xbffff270
vals: one.s = 0x52a0, one.e = 0xbffff270
One sees that the address of one.s and one.e are equal – as expected – but the values aren’t.
This is what confuses me.
one.e is the address of the one.e array. one.s is the value of one.s. If you want the value of e you need to access one.e[0]…one.e[3].