I'm taking the following example from The Fundamentals of Programming course:
enum color = { red, orange, yellow };
enum fruit = { apple, orange, kiwi}; // error: orange is redefined
int kiwi = 42; // error: kiwi is redefined
The author added a note:
An enumeration with
=
will give the identifier the provided value, which remains as start value for the next enumerators.
Is the code above valid? I mean, when should we (not) use =
to create enumerations?
Trying to compile:
enum fruit = { apple, orange, kiwi};
main() {}
I get the following error:
$ gcc main.c
main.c:1:12: error: expected identifier or ‘(’ before ‘=’ token
enum fruit = { apple, orange, kiwi};
If I remove the =
character, the file is compiled fine.
So, what's the usage of the equal character?