Search code examples
ccompiler-constructionenums

Enumerator value resolution


In which stage of the compilation do enumerator values get resolved?

Eg:

enum numbers
{
    ZERO,
    ONE,
    TWO
};

int main()
{
    int var = ZERO;
    return 0;
}

In which stage of the compilation does the token ZERO get replaced with 0?


Solution

  • enums are not pre-compiler directives, so ZERO does not get replaced by 0. They are evaluated like structs, unions etc. at the compilation time.