DIM Basic432

From BeebWiki
Jump to: navigation, search


Correction to the DIM statement for BASIC 4r32.

HIBASIC 4.32 added the following check in the Multiply Upper Dimension by Lower Dimension routine:

      [&95E4] BCS 11 --> &95F1 Bad Dim error

this occurs after we have multiplied &2A-&2B by 2, and avoids memory corruption if the number of elements to dimension (&2A-&2B) is too large. This check now correctly disallows arrays to be DIMmensioned, where the number of elements would exceed 65535 (&FFFF). In BASIC IV, DIM K(1582,127) was allowed (total of 200914 elements!) which caused the following weird bug:

>L. 
10 DIM K(1582,127) 
20 FOR I% =1 TO 1582 
30 FOR J%=1 TO 127 
40 K(I%,J%)=56.77777 
50 NEXT J% 
60 NEXT I% 
>RUN 

Array at line 40 
>L. 
0 DIM K(1582,127) 
0 FOR I% =1 TO 1582 
0 FOR J%=1 TO 127 
0 K(I%,J%)=56.77777
0 NEXT J% 
0 NEXT I%
>

Memory was corrupted, causing BASIC to become confused. In BASIC4 r32, DIM K(1582,127) now produces 'Bad DIM' error.