[fpc-pascal] Const Array Length (was Dynamic Array Length)

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Jan 3 13:12:28 CET 2010

On 03 Jan 2010, at 13:03, Frank Peelo wrote:

> Rainer Stratmann wrote:
>> Am Saturday 02 January 2010 16:34:57 schrieb JoshyFun:
>>> a: array[1..] or string = ('aaa', 'bbb', 'ccc');
>> That would be perfect.
>> Then you can automatically calculate the amount:
>> amax = sizeof( a ) div sizeof( a[ 1 ] );
> If this syntax was in Pascal, would you use
> High(a)-Low(a)+1
> rather than sizeof()?

Even easier is length(a) in this case. As a bonus, low/high/length won't break when you use a dynamic or open array, while C-style sizeof calculations will break in such cases.


More information about the fpc-pascal mailing list