[fpc-pascal] Array initialization
Marc Santhoff
M.Santhoff at web.de
Wed Mar 18 07:35:32 CET 2009
Am Dienstag, den 17.03.2009, 19:50 -0400 schrieb Francisco Reyes:
> 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.
>
> Examples there..
> var
> c1 : array[1..10] of char := '123456';
> int2 : array[1..100] of integer := [50 of 1, 50 of 2];
>
> Tried those, but didn't seem to to work.
Use only '=' instread of ':='.
Working is e.g.:
<code>
vector: array[0..6] of longint = (1, 2, 3, 4, 5, 6, 7);
type
particle_t = record
name: array [0..Pred(16)] of char;
longi: integer;
pressure: float;
temperature: double;
lati: integer;
end;
wbuf: array [0..Pred(NRECORDS_C)] of particle_t = (
(name:'zero'#0; longi:0; pressure:0.0; temperature:0.0; lati:0),
(name:'one'#0; longi:10; pressure:1.0; temperature:10.0; lati:10),
...
</code>
> Is a loop the only way to initialize all the values in an array other than
> Values: array[1..2] of integer = (0,0);
> In the program I am working on, Values will be an array of 128
> integers and
> I would like to initialize them to 0.
Use fillchar() as others mentioned.
--
Marc Santhoff <M.Santhoff at web.de>
More information about the fpc-pascal
mailing list