[fpc-pascal] Const Array Length (was Dynamic Array Length)
Juha Manninen
juha.manninen at phnet.fi
Sat Jan 2 16:01:35 CET 2010
On torstai, 31. joulukuuta 2009 16:33:50 Anthony Walter wrote:
> No, the compiler will not fill in the array length based on your element
> list. It does compute the length while compiling and *you* need to match it
> in your declaration.
In most cases it would be better if the compiler counted the number of
elements. Only in few cases the programmer really wants to limit the number to
some predefined value.
The currently used syntax for const array is:
const
a: array[1..3] of string = ('aaa', 'bbb', 'ccc');
Already years ago I proposed the following syntax in Delphi mailing list:
const
a: array of string = ('aaa', 'bbb', 'ccc');
It looks like a dynamic array, but obviously is not dynamic because it is
constant. :-)
The indexing would start from 0 like with dynamic arrays.
It would not break the existing syntax and would be very intuitive.
In the current syntax if I add one element, I need to change the upper bound
number, too, which feels really stupid. In the proposed syntax I would not
need to change any bounds.
In Delphi mailing list the answers were basically like:
The syntax is perfect now. Keep on changing the bounds.
How about FPC? This change would not be Delphi compatible apparently.
Regards,
Juha Manninen
More information about the fpc-pascal
mailing list