title: Multiple names for the same struct in c
body: <p>Is it possible to create multiple names for the same struct in C?
  The idea is that data structures in a communication protocol which has the same layout but different names, could share the same definition.</p>
  
  <p>Example:</p>
  
  <pre><code>struct flags_type1 {
          uint8_t flag1;
          uint8_t flag2;
  };
  
  struct flags_type2 {
              uint8_t flag1;
              uint8_t flag2;
  };
  /* The flag layout for type 2 is identical to type 1, so somehow
   * just reuse the struct for type 1, but with a new name.
   * (For readability in the implementation. */
  
  /* *** HERE: Insert solution code here. Something with typedef? *** */
  
  struct flags_type3 {
          uint8_t flag1;
          uint8_t flag2;
          uint8_t flag3;
  };
  
  struct msg_object {
          uint8_t type_id_code;
          union {
                  struct flags_type1 type1;
                  struct flags_type2 type2;
                  struct flags_type3 type3;
           } flags;
           uint8_t payload[7];
  };
  
  
  /* Utilization: */
  struct msg_object *msg;
  switch (msg-&gt;type_id_code) {
  case TYPE1:
          do_things_type1(msg-&gt;flags.type1);
          break;
  case TYPE2:
          do_things_type2(msg-&gt;flags.type2);
          break;
  case TYPE3:
          do_things_type3(msg-&gt;flags.type3);
          break;
  }
  </code></pre>
  
  <p>Motivation:
  I am implementing a communication protocol which can transmit message objects which has different types (Specifically, SDOs in CANopen). Each object has a 5-bit field of status flags, and some of the objects has an identical layout of this field. There is also a 3-bit field which identifies the object type. These two fields, are fitted into a single byte.</p>
  
  <p>The idea is thus to utilize the correct flag layout based on the type identifier. To make this choice of flag layout intuitive, it seems sensible to make all the type names present, without defining the same layout twice.</p>
  
  <p>I suppose this, technically, is a inheritance question.</p>
  
  <p>//audun</p>