Toby
Toby

Reputation: 10144

C enum tags before and after list - type or var name?

I see a lot of occasions (googling) where enums are declared as follows:

enum enum_tag {a = 0, b, c, d} tag_again;

enum enum_tag {a = 0, b, c, d};

or

enum {a = 0, b, c, d} tag_again;

Some times it seems like enum_tag is the type and tag_again is a variable name, but if enum_tag is not present tag_again seems to sometimes be used as either.. which is it?

If I were to code enum {a = 0, b, c, d} tag_again; Is tag_again an enum type or variable of a nameless enum type??

Upvotes: 4

Views: 906

Answers (1)

Toby
Toby

Reputation: 10144

Continued my googling and MSDN gave me the answer: MSDN C Enum Declarations

enum enum_tag {a = 0, b, c, d} tag_again; defines an enum type enum_tag and declares a variable of that type: tag_again.

enum enum_tag {a = 0, b, c, d}; defines an enum type of enum_tag

and

enum {a = 0, b, c, d} tag_again; declares a variable tag_again of a nameless enum type (as I thought)

Upvotes: 6

Related Questions