Pointers to Nul-Terminated and fixed-length strings

A declaration of an Nul-Terminated or fixed-length string must explicitly state the maximum length of the string, in order for the compiler to allocate memory accordingly. When declaring pointers to fixed-length strings, you may also state the maximum length of the string. This will allow INCR and DECR to move the pointer to the next or previous string, respectively. If you do not supply the length for a fixed-length string pointer, INCR and DECR will move the pointer by one byte.

However, with an Nul-Terminated string pointer, the length limit may be explicitly stated, or it may be left as an ambiguous value, by skipping the length clause entirely. For example, the following lines are valid:

DIM x AS ASCIIZ PTR * 41

DIM y AS STRINGZ PTR * 2

DIM z AS WSTRINGZ PTR

This rule applies to scalar pointers, arrays of pointers, pointers as function parameters, and pointers as members of a User-Defined Type or Union. If the optional length limit is specified, PowerBASIC will always truncate a string assignment to fit correctly in the memory allocated to the variable.

If the length is ambiguous, it becomes the programmer's responsibility to ensure the target buffer is not overflowed leading to memory corruption or General Protection Faults (GPF). Use caution in this case.

See Also

Pointers (@)

Pointers to arrays

Pointers to arrays with dual indexes