I would like to create enum
and structs in c
.
However, I need the enum
to be inside another struct
(to avoid duplicating the name). Something like this:
#include <stdio.h>
// 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;
}
In fact, I want to use struct
for my enum
and then use that enum
as a separate type in another structure and then call the last structure as a complete type but I get these errors:
error: expected specifier-qualifier-list before 'typedef'
typedef enum {
error: expected expression before ':' token
header_n::Name key; // using top enum
error: bit-field '<anonymous>' width not an integer constant
header_n::Name key; // using top enum
error: bit-field '<anonymous>' has invalid type
error: 'header_t {aka struct <anonymous>}' has no member named 'key'
header.key = header_n::Agent;
error: expected expression before 'header_n'
header.key = header_n::Agent;