Unlike Golang (a language living in 1970), C has explicit support for enums (enumerations) with the enum keyword.
TJ is salty because Go is a simple, modern language that companies ackshually use to ship products. Not all programming languages can be academic thought-experiments like OCaml.
You can define a new enum type like this:
typedef enum DaysOfWeek {
MONDAY,
TACO_TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
FUNDAY,
} days_of_week_t;
The typedef and its alias days_of_week_t are optional, but like with structs, they make the enum easier to use.
In the example above, days_of_week_t is a new type that can only have one of the values defined in the enum:
MONDAY, which is 0TACO_TUESDAY, which is 1WEDNESDAY, which is 2THURSDAY, which is 3FRIDAY, which is 4SATURDAY, which is 5FUNDAY, which is 6You can use the enum type like this:
typedef struct Event {
char *title;
days_of_week_t day;
} event_t;
// Or if you don't want to use the alias:
typedef struct Event {
char *title;
enum DaysOfWeek day;
} event_t;
An enum is not a collection type like a struct or an array. It's just a list of integers constrained to a new type, where each is given an explicit name.
The Sneklang graphics library needs to represent colors.
Create a Color enum (and the color_t typedef) with RED, GREEN, and BLUE values, in that order.