I was a little confused with typedef / enum until I realized that I didn't need to call emun. Are there any differences / advantages between the two when used with typedef, the second seems a lot easier for me to understand.
First example:
typedef enum enumMenuItems {
none,
add,
save,
load,
list,
remove
} menuItems;
menuItems optionSelect = none;
Second example:
typedef enum {
Earth = 1,
Mars,
Saturn,
Neptune,
Jupiter
} planets;
planets closest = Mars;
.
EDIT:
typedef enum enumMenuItems {
none,
add,
save,
load,
list,
remove
} menuItems;
Thus, the above essentially defines two types: one enumeration called enumMenuItems, and the second a typedef enumMenuItems called menuItems.
menuItems optionSelect = save;
enum enumMenuItems optionSelect = save;
The above two declarations are essentially the same: one uses a typedef, and the other enum. Therefore, if you use typedef, you can leave your enum unnamed as a type that can be accessed through typedef menuItem.
Gary
source
share