|
|
1.1 ! root 1: ! 2: ! 3: enum C Keyword enum ! 4: ! 5: ! 6: ! 7: ! 8: Declare a type and identifiers ! 9: ! 10: ! 11: An enum declaration is a data type whose syntax resembles those ! 12: of the struct and union declarations. It lets you enumerate the ! 13: legal value for a given variable. For example, ! 14: ! 15: ! 16: enum opinion {yes, maybe, no} GUESS; ! 17: ! 18: ! 19: declares type opinion can have one of three values: yes, no, and ! 20: maybe. It also declares the variable GUESS to be of type ! 21: opinion. ! 22: ! 23: As with a struct or union declaration, the tag (ooppiinniioonn in this ! 24: example) is optional; if present, it may be used in subsequent ! 25: declarations. For example, the statement ! 26: ! 27: ! 28: register enum opinion *op; ! 29: ! 30: ! 31: declares a register pointer to an object of type opinion. ! 32: ! 33: All enumerated identifiers must be distinct from all other iden- ! 34: tifiers in the program. The identifiers act as constants and be ! 35: used wherever constants are appropriate. ! 36: ! 37: COHERENT assigns values to the identifiers from left to right, ! 38: normally beginning with zero and increasing by one. In the above ! 39: example, the values of yes, no, and maybe are set, respectively, ! 40: to one, two, and three. The values often are iinntts, although if ! 41: the range of values is small enough, the enum will be an unsigned ! 42: char. If an identifier in the declaration is followed by an ! 43: equal sign and a constant, the identifier is assigned the given ! 44: value, and subsequent values increase by one from that value; for ! 45: example, ! 46: ! 47: ! 48: enum opinion {yes=50, no, maybe} guess; ! 49: ! 50: ! 51: sets the values of the identifiers yes, no, and maybe to 50, 51, ! 52: and 52, respectively. ! 53: ! 54: ***** See Also ***** ! 55: ! 56: C keywords ! 57: ! 58: ! 59: ! 60: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.