title: C++ understanding Unions and Structs
body: <p>I've come to work on an ongoing project where some unions are defined as follows:</p>
  
  <pre><code>/* header.h */
  typedef union my_union_t {
    float data[4];
    struct {
      float varA;
      float varB;
      float varC;
      float varD;
    };
  } my_union;
  </code></pre>
  
  <p>If I understand well, unions are for saving space, so sizeof(my_union_t) = MAX of the variables in it. What are the advantages of using the statement above instead of this one:</p>
  
  <pre><code>typedef struct my_struct {
    float varA;
    float varB;
    float varC;
    float varD;
  };
  </code></pre>
  
  <p>Won't be the space allocated for both of them the same?</p>
  
  <p>And how can I initialize varA,varB... from <em>my_union</em>?</p>