Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-02

Nice const array messages. Thanks!

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

I just noticed this really nice compiler feature. I don't know when it as added but it's really helpful.

When defining const array like below the compiler will tell you how many elements are missing:

const
  Food: array[0..7] of string = (
    'Apple', 'Banana', 'Cherry', 'Doughnut', 'Eclair');

Error: Expected another 3 array elements

And when you have too few elements in the array in it will make tell you the point where it expected the array to end.

const
  Food: array[0..2] of string = (
    'Apple', 'Banana', 'Cherry',| 'Doughnut', 'Eclair');

Fatal: Syntax error, ")" expected but "," found,

And in Lazarus the caret is placed where the array should have ended "|".

This is really great feature and helps a lot when declaring array constants with many items. Thank you to whomever added this to the compiler :)

Reply by email