[fpc-pascal] Initializing record variables
Marco van de Voort
marcov at stack.nl
Fri Nov 10 11:08:31 CET 2006
> I have to translate a lot of assignements like this:
>
> particle_t = record
> name: array [0..Pred(16)] of char;
> longi: integer;
> pressure: float;
> temperature: double;
> lati: integer;
> end;
>
> ibuf: array [0..Pred(2)] of particle_t;
>
> (* raw translation by automatic tool *)
> ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0));
>
> from C to pascal. To make it easier I'd like to write something like:
>
> ibuf: array [0..Pred(2)] of particle_t = ???
>
> analoguous to
>
> i: integer = 42;
>
> Is there any syntax allowing to do so? If yes, it would be very easy to
> do instead of addressing each record field by name for any record in the
> target array.
As a global constant: yes. Locally, no.
So
int func ()
{xarray i = ((arrayconst));
}
translates roughly to
var constant_func_1_array : xarray = ((1,4,2,2),(3,3,3,3));
function func:cint;
var i : xarray;
begin
i:=constant_func_1_array;
end;
If you have your automatic tool in src, you might be able to hack it in.
More information about the fpc-pascal
mailing list