Seeking C Union clarity
Posted
by mustISignUp
on Stack Overflow
See other posts from Stack Overflow
or by mustISignUp
Published on 2010-05-20T11:37:49Z
Indexed on
2010/05/20
11:40 UTC
Read the original article
Hit count: 236
typedef union {
float flts[4];
struct {
GLfloat r;
GLfloat theta;
GLfloat phi;
GLfloat w;
};
struct {
GLfloat x;
GLfloat y;
GLfloat z;
GLfloat w;
};
} FltVector;
Ok, so i think i get how to use this, (or, this is how i have seen it used) ie.
FltVector fltVec1 = {{1.0f, 1.0f, 1.0f, 1.0f}};
float aaa = fltVec1.x;
etc.
But i'm not really groking how much storage has been declared by the union (4 floats? 8 floats? 12 floats?), how? and why? Also why two sets of curly braces when using FltVector {{}}?
Any pointers much appreciated (sorry for the pun)
© Stack Overflow or respective owner