OpenConsole()
;
Dim a.l(10)
Structure array
a.l[10]
EndStructure
DefType.array b
n=10
For i=0 To n : a(i)=i :Next
For i=0 To n : b\a[i]=i :Next
n.l=Val(Input())
CloseConsole()
End
In the above code you can use elements 0-10 of the array defined in the DIM statement (that is, 11 elements) without the Debugger protesting about out of bounds. For the array declared in the structure however it works as I would expect, i.e. b\a[10] gives an out of bounds. Is this really as intended? Do I really get an 11 element array when I declare
Dim a.l(10), or is it the Debugger?
Yes, in structure an array [] doesn't behave like the normal BASIC array behaviour to conform to C/C++ structure format (to allow direct API structure porting). This means than a[2] will allocate an array from 0 to 1 where Dim a(2) will allocate an array from 0 to 2. It should be added to the docs, I agree.
Thanks for clarifying that. On the basis of the documentation I had expected that Dim a.l(10) would give you 10 elements, especially given the example of a 2-dim array with the number of columns and lines. I am not familiar with the standard BASIC definitions, do BASIC arrays also start with index 0 instead of 1? If they start with 1 (a much more reasonable choice in my view, but I lose against the enormous influence of C\C++ ) it would all make more sense....
> do BASIC arrays also start with index 0 instead of 1?
In every Basic I've used (from the Vic-20 up) arrays always start at index
number 0. So Dim MyArray(5) is actually 6 arrays. I think Visual Basic
lets you start at 1 instead, but since getting PureBasic I haven't touched
VB and can't be 100% sure of that anymore.