Are default enum values in C the same for all compilers?

SSS picture SSS · Jun 22, 2011 · Viewed 67.1k times · Source

When declaring an enum as shown below, do all C compilers set the default values as x=0, y=1, and z=2 on both Linux and Windows systems?

typedef enum {
    x,
    y,
    z
} someName;

Answer

James McNellis picture James McNellis · Jun 22, 2011

Yes. Unless you specify otherwise in the definition of the enumeration, the initial enumerator always has the value zero and the value of each subsequent enumerator is one greater than the previous enumerator.