title: c using enum inside struct
body: <p>I would like to create <code>enum</code> and structs in <code>c</code>.
  However, I need the <code>enum</code> to be inside another <code>struct</code> (to avoid duplicating the name). Something like this:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  // define structure as our enum namespace
  typedef struct {
      typedef enum {
          Host,
          Cookie,
          Agent
      } Name;
  } header_n;
  
  typedef struct {
      header_n::Name key; // using top enum
      char value[128];
  } header_t;
  
  int main() {
  
      header_t header;
      header.key = header_n::Agent;
  
      return 0;
  }
  </code></pre>
  <p>In fact, I want to use <code>struct</code> for my <code>enum</code> and then use that <code>enum</code> as a separate type in another structure and then call the last structure as a complete type but I get these errors:</p>
  <pre><code>error: expected specifier-qualifier-list before 'typedef'
       typedef enum {
  
  error: expected expression before ':' token
       header_n::Name key; // using top enum
  
  error: bit-field '&lt;anonymous&gt;' width not an integer constant
       header_n::Name key; // using top enum
  
  error: bit-field '&lt;anonymous&gt;' has invalid type
  
  error: 'header_t {aka struct &lt;anonymous&gt;}' has no member named 'key'
       header.key = header_n::Agent;
  
  error: expected expression before 'header_n'
       header.key = header_n::Agent;
  </code></pre>