An enumeration (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
enum) is a user-defined data type consisting of a set of named integer constants known as enumerators. In C, individual enumerators are strictly of type int, while the enumeration type itself is represented by an implementation-defined integer type capable of holding all defined enumerator values.
Syntax
tag_name: An optional identifier that names the enumeration type.enumerator_list: A comma-separated list of identifiers. A trailing comma is permitted in modern C (C99 onwards).variable_list: An optional comma-separated list of variable instances declared immediately alongside the type definition.
Declaration Patterns
1. Tagged Declaration Defines the enumeration type using a tag. Subsequent variable declarations must include theenum keyword.
enum keyword during variable instantiation.
Enumerator Value Assignment
By default, the compiler assigns the integer value0 to the first enumerator and increments the value by 1 for each subsequent enumerator. This behavior can be overridden by assigning explicit integer constant expressions.
Scope and Namespace Rules
- Enumerator Scope: Enumerators are injected directly into the enclosing scope of the
enumdeclaration. C does not support scoped enumerations; accessing an enumerator via its tag (e.g.,State.IDLE) is a syntax error. The identifier is simplyIDLE. - Identifier Uniqueness: Because enumerators leak into the enclosing scope, two different enumerations within the same scope cannot share an enumerator identifier.
- Tag Namespace: The
tag_nameoccupies the C tag namespace (shared withstructandunion). It can share an identifier with a variable or function, but it cannot share an identifier with another struct, union, or enum tag in the same scope.
Master C with Deep Grasping Methodology!Learn More





