ENUM question

How to I make a set of variables in an enum set. set to a specific value?

say I have
1
2
3
4
5
6
7
  enum game
{
win,
loss,
tie
};

how do I make it so that win is 1 loss is 2 and tie is 9?
By writing something like this:
1
2
3
4
5
enum game {
  win  = 1,
  loss = 2,
  tie  = 9,
};
Last edited on
@mbozzi
Your example is wrong.

1
2
3
4
5
enum game {
  win  = 1,
  loss = 2,
  tie  = 9 // Note : No colon (,) here
}
No, my example is correct.
It compiles, and is standard-compliant. A single trailing comma is allowed. Check the grammar, here.
http://www.nongnu.org/hcb/#enum-specifier

Your correction, OTOH, is missing a semicolon at the end of the enumeration definition :D.
closed account (48T7M4Gy)
http://en.cppreference.com/w/c/language/enum

It is incorrect to say either one or the other is incorrect. :)
PS It is a comma, not a colon. :(
Last edited on
Topic archived. No new replies allowed.