[fpc-devel] Multiple variable initialization

Anton Shepelev anton.txt at gmail.com
Sat Mar 31 11:34:33 CEST 2018


Ondrej Pokorny:

> Is  there  a reason why multiple variable initial-
> ization is forbidden?
>
> program Test;
> var
>    A:    Integer = 0; // allowed
>    B, C: Integer = 0; // not allowed
> begin
> end.
>
> Will a patch be applied that allows it?

That means another complication of the language,  to
which it is not well suited, c.f. the C style:

   int A = 0, B = 1, C = 2;

Initialisation is a special and redundant way to as-
sign a value to a variable.  Is this mixing of  dec-
laration  and action a good idea?  Why not keep them
separate?

If you must save vertical space, write your  initial
assignments on one line:

   var A, B, C: Integer;
   begin
      A := 1; B := 2; C := 3;
      { work }
   end;

-- 
Please, do not forward replies to my e-mail.




More information about the fpc-devel mailing list