Enums


Enums are another way the user can use to define a custom data type. Unlike the ones we've seen before, enums cannot have user-defined fields which can contain data: they are simply signed integers (of the smallest possible size the compiler can use for the given values) that maps a series of user-defined, human readable aliases to values.

Syntax


In [name], enum declaration is done as such:

enum *name* ( *values* );

Values are comma-separated, and the value mapping itself can be automatic, manual, or both.

identifier // Automatic mapping

identifier : value // Manual mapping

Keep in mind values can only be mapped to signed integer literals.

Examples


[might be a bad example, i cant really think of others tho] enum Signal ( SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM )

This defines an enum, Signal, containing 6 automatically mapped values. The compiler sees this enum as an i8.

To access a value, you need to specify the enum it is a member of:

Signal.SIGTERM // corresponds to an i8 of value 5

If you want to just use it as macro without needing to specify the parent enum, you can just use constants. No need for enums. Keep in mind, enums are data types, not collections of macros.

Behaviour


There are no pragmas to alter the default behaviour of enums.