[fpc-pascal] Array initialization
leledumbo
leledumbo_cool at yahoo.co.id
Wed Mar 18 04:33:52 CET 2009
> On the following URL,
> http://web.mit.edu/sunsoft_v5.1/www/pascal/lang_ref/ref_data.doc.html#1212,
> I found some different syntax to initialize an array.
That's another Pascal extension from Sun. One of the problem (and power) of
Pascal is that it's often extended arbitrarily, because no standard (other
than too simple ISO 7185 and too complicated ISO 10260) exists.
Remember that FPC tries to be compatible with Delphi (at least until version
7) and Turbo Pascal (also version 7), while adding its own extensions.
> c1 : array[1..10] of char := '123456';
In this case, FPC still follows (not 100 % conforms) the standard. c1 is a
fixed length array, therefore only strings of the same length can be
assigned to it. If you want to follow standards, pad it with spaces.
Otherwise, use String[10].
> int2 : array[1..100] of integer := [50 of 1, 50 of 2];
This is like C's array initialization (extended maybe), which is not
supported. Either fill all or do it in a statement. You can fill some
followed by FillXXX which is the most commonly used method as it doesn't
involve looping (MUCH faster).
IMHO, FPC should consider this kind of extension though (partial filling).
> begin
> fillchar(c1[1],5,0);
> fillchar(c1[5],5,#32);
>
> You might need @ sign in front of c1 though...
AFAIK, no. FillChar doesn't expect pointers, the above is already correct
(note that it's syntactically correct, but it will fill the wrong data if
you add @).
--
View this message in context: http://www.nabble.com/Array-initialization-tp22570315p22572320.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list