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

Const array design

One-dimensional lookup

const-array-lookup.gpc
const uint8 CURVE[] = { 0, 3, 7, 13, 22, 35, 52, 72, 100 };
int index;
int output;

main {
    index = 5;
    if(index >= 0 && index < sizeof(CURVE)) {
        output = CURVE[index];
    }
}

Two-dimensional records

const-array-2d.gpc
const int16 PROFILES[][] = {
    { 10, 20, 30, 40 },
    { 15, 25, 35, 45 },
    { 20, 30, 40, 50 }
};

int profile;
int point;
int value;

main {
    profile = 1;
    point = 2;
    value = PROFILES[profile][point];
}

Every row must have equal length. A 2D const array normally requires both indexes; address-style string/image/ADT access is a special case.


Choose the narrowest correct type

  • Use int8 / uint8 for byte-scale values.

  • Use int16 / uint16 for medium tables.

  • Use int32 only when the range requires it.

Narrower element types can materially reduce bytecode size. Let the compiler's fit suggestions guide safe narrowing to 8- or 16-bit elements.

Last updated