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

Runtime variables

GPC has one runtime variable type: the signed 32-bit integer, written as int. You can declare one value at a time or reserve a consecutive group of values as an array.


Scalar integers

Use a scalar integer when a name needs to hold one value:

int count;
int strength = 25;
int x, y, enabled;

Rules:

  • Declarations are global and top-level only.

  • Uninitialized variables start at zero.

  • There is no runtime bool, float, string, object, struct, or local block variable type.

  • Function parameters are local integer values.

  • Arithmetic overflow wraps according to the VM's integer behavior; design ranges to avoid relying on overflow.

  • Runtime division truncates: 10 / 3 is 3, 3 / 4 is 0.


Scaled-integer pattern:

scaled-integer-pattern.gpc
// 125 means 1.25x; calculate percentage before dividing away precision.
int base = 40;
int scale_percent = 125;
int result;

main {
    result = (base * scale_percent) / 100;
}

Check that the multiplication cannot exceed the 32-bit range.


Runtime arrays

Use an array when you need several related runtime values under one name:

Runtime arrays:

  • occupy one variable slot per element;

  • start filled with zero;

  • cannot have initializers;

  • require an index in range 0..size-1;

  • can use constant or runtime indexes;

  • are mutable.

The compiler catches constant out-of-range indexes on ordinary declared arrays. You must validate dynamic indexes yourself.


Sequential variable storage and aliases

Runtime variables are allocated sequentially after any variable slots generated by the compiler. GPC's indexing syntax operates on those sequential slots, so any runtime variable can technically be used as the base of an indexed access—not only a name declared with [size].

This is an advanced aliasing behavior, not a substitute for a properly declared array. It can silently reach an unrelated variable when declarations change, so use it only when the storage layout is intentional and documented.


A zero-sized array occupies no slots and aliases the next declared variable:

The compiler warns about this accepted quirk. A zero-sized array with no eligible variable after it is an error because it would point beyond the allocated variable table.

Last updated