Page 1 of 1

array allocation

Posted: Sun Feb 10, 2013 8:53 pm
by YahooArchive
>from help line
>I don\'t quite understand the rules of arrays in your system. I am not sure if
I should be subtracting 1 from the number of elements or adding one. Can you
please clarify?

>Example:

>I am receiving 16 bytes frames from RXD1 and I want to put them in a 16 element
array per cycle. Which would be more appropriate given the rules of ARMBasic? I
am using an ARMite PRO

>dim b(15)?
>dim b(16)?
>dim b(17)?

ARMbasic follows the Visual BASIC convention. Space is allocated from element
0, but it also allocates the last element, which goes back to earlier BASICs.

DIM B(15) ' allocates 16 elements from 0 to 15

Re: array allocation

Posted: Sun Feb 10, 2013 8:54 pm
by YahooArchive
I found Help somewhat confusing...

It says "The size is the number of elements in the array plus 1"

Is that correct?

=======================

DIM symbolname (size )
.....
Description
......
DIM is used to assign arrays of integers or strings (arrays of bytes). The
size is the number of elements in the array plus 1. This allows indexing from 0
to size .

Re: array allocation

Posted: Sun Feb 10, 2013 8:55 pm
by YahooArchive
Maybe that example should use the names max and size.

And it is confusing, mainly to be backward compatible with earlier BASICs which
allocated from 1 to max. And to accomodate C like arrays which begin at 0.

If you Google Visual BASIC array allocation, from the Microsoft site

Dimension Length
The index of each dimension is 0-based, which means it ranges from 0 through its
upper bound. Therefore, the length of a given dimension is greater by 1 than the
declared upper bound for that dimension.