For the complete documentation index, see llms.txt. This page is also available as Markdown.

Enumerations

Enums create related compile-time integer names. Use them for state machines, modes, pages, or schema versions:

enum-modes.gpc
enum {
    MODE_OFF,       // 0: the first implicit value starts at zero
    MODE_STANDARD,  // 1: implicit values increment by one
    MODE_ALTERNATE, // 2
    MODE_COUNT      // 3
};

int mode;

main {
    if(event_press(PS5_TRIANGLE)) {
        mode = mode + 1;
        if(mode >= MODE_COUNT) mode = MODE_OFF;
    }
}

An explicit value restarts the sequence from that point:

enum {
    PAGE_HOME,       // 0
    PAGE_STATUS,     // 1
    PAGE_EDIT = 10,  // 10: explicitly restart here
    PAGE_SAVE,       // 11
    PAGE_ADMIN = 20, // 20: restart again
    PAGE_DIAGNOSTIC  // 21
};

Enum members share the data-symbol namespace with variables, definitions, and const-data names. Do not reuse an enum-member name for one of those declarations.

Last updated