[fpc-pascal] Are record fields zeroed on declaration of a record?

Ryan Joseph genericptr at gmail.com
Thu Oct 8 18:31:26 CEST 2020



> On Oct 8, 2020, at 5:14 AM, gabor via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> You can define typed constant and assign it to variable.
> 
> type
>  TMyRecord = record
>    X, Y: Integer;
>    S: String;
>  end;
> 
> const
>  MYDEFREC: TMyRecord = (X: 1; Y: 2; S: 'ABC');

I never understood why we can't initialize fields at init time for records. Pascal seems to be the only language that doesn't support this in 2020. Thinking of C++, C#, PHP, Swift and many more all let you do this. Not even Delphi supports this AKAIK.

type
 TMyRecord = record
   X, Y: Integer = 0;
   S: String = '';
 end;


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list