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

sizeof and addr

sizeof(CONST_OR_ARRAY) is evaluated at compile time and returns the declared element/row size understood by the compiler. It is useful for bounded loops:

sizeof-bounded-loop.gpc
const uint8 BUTTONS[] = { PS5_CROSS, PS5_CIRCLE, PS5_SQUARE };
int i;

main {
    for(i = 0; i < sizeof(BUTTONS); i++) {
        if(get_ival(BUTTONS[i])) {
            set_val(TRACE_1, i);
        }
    }
}

Zen Studio Live also accepts supported type keywords in sizeof(type). For the fixed-width numeric types, the result is their storage width in bytes:

Type expression
Result

sizeof(int8) / sizeof(uint8)

1

sizeof(int16) / sizeof(uint16)

2

sizeof(int32)

4

define PROFILE_VALUE_BYTES = sizeof(int16);
define SERIAL_VALUE_BYTES = sizeof(int32);

Type support is target-specific. If a keyword has no fixed supported size on the selected target, the compiler reports that sizeof(keyword) is not supported.

addr(CONST_ITEM) produces a const-data address for APIs that consume strings, images, or adaptive-trigger records. It is not a pointer to a runtime variable and cannot be used on arbitrary expressions.

Last updated