ENUM in C

Isshiki🐈
1 min readAug 12, 2020

TL;DR

Enum in C allows you only to pretend to have a custom type that works like a gear stick. As an example, you can have enum gearbox my_speed = reverse; though they are only loosely organised and you can even do my_gearstick = 1;

Enum is one of the weirdest “things” to me. It looks just like struct and even union but does quite different things.

enum res { yes, no };

It’s loosely organised. Enumerators, yes and no, are just two integer constants (rvalues they are, actually) and may appear wherever constants are required and a variable of such a type, declared as enum res func_result; may just work as any variable of the type int that is, you may even func_result = 1;

So yes, I think it’s safe to say that enumerations are a notational convenience than anything else. They are not like struct or union which provide new structures and have their own constraints, and you can do whatever you do with enumerations with a few more variables but with enumerations, you keep your data tidy and clean.

--

--