Reputation: 15598
I'm having problems with an enum type. I have the following in my header:
enum map_type_t{
MAP_TYPE_PORT,
MAP_TYPE_VLAN,
MAP_TYPE_L2MAC,
MAC_TYPE_VPWS,
MAC_TYPE_BFD,
MAC_TYPE_VPLS
};
I included the header in my C
file and that's eherre I have a prototype like int store_to_flash (map_type_t map_type, void* pData)
but now, for some reason, the type map_type_t
isn't being recognized, why not I'm wondering? I've also tried to typedef the enum instead but couldn't get that working either, it looked like:
typedef enum {
MAP_TYPE_PORT,
MAP_TYPE_VLAN,
MAP_TYPE_L2MAC,
MAC_TYPE_VPWS,
MAC_TYPE_BFD,
MAC_TYPE_VPLS
}map_type_t;
What's the problem, I don't understand.
PS: this is with the diab
compiler in C99
mode
edit 1
interesting, if I move
typedef enum map_type_e {
MAP_TYPE_PORT,
MAP_TYPE_VLAN,
MAP_TYPE_L2MAC,
MAC_TYPE_VPWS,
MAC_TYPE_BFD,
MAC_TYPE_VPLS
}map_type_t;
from my header into the C file on the very top, after my include
s it seems to work just fine... now that's odd isn't it? Any idea why that might be?
Upvotes: 0
Views: 122
Reputation: 263237
The declaration
enum map_type_t { /* ... */ };
creates a type named enum map_type_t
. The identifier map_type_t
is a tag, not a type name.
You can either use a typedef
to create an alias for the type, or you can refer to it by its name enum map_type_t
. (The typedef
in your question should have worked; we'd have to see more code to know why it didn't work for you.)
Similar rules apply to struct
and union
type declarations.
(The rules are different in C++.)
Upvotes: 2