There are three ways in BBC BASIC of creating an
un-dimensioned array, that is an array which exists (its name is present in the global namespace) but it has never been DIMensioned, so there is no storage allocated to it. If you need to, you can determine this state by reading its pointer.
The first is by making it LOCAL:
Code: Select all
DEF PROCtest
LOCAL array()
REM Here the array exists but it has not been DIMensioned
PRINT PTR(array()) : REM prints 1
The second is by making it PRIVATE (assuming it was not DIMmed in a previous call to the same function):
Code: Select all
DEF PROCtest
PRIVATE array()
REM Here the array exists but it has not been DIMensioned
PRINT PTR(array()) : REM prints 0
The third is by passing it to a function as a RETURNed parameter (assuming it was not DIMmed previously):
Code: Select all
DEF PROCtest(RETURN array())
REM Here the array exists but it has not been DIMensioned
PRINT PTR(array()) : REM prints 0
So to detect an array in this state, check whether its pointer is
zero (global or PRIVATE) or
one (LOCAL).