[fpc-pascal] Option type

denisgolovan denisgolovan at yandex.ru
Wed Jun 2 13:28:46 CEST 2021

> Well as already discovered type like strings can not go into a "record case"
> But... The above record is anyway of constant size. I.e. the memory for
> the field is always included, even if it is not used.
> Since the "false" block is empty, you can do
> type
> generic TOption<T> = record
> IsSome:boolean;
> some: T;
> end;
> It is not as expressive to the reader of the code. But it leads to the
> same data in memory.

Except that "some" is still initialized with something (some default) and dropped and copied and assigned despite conceptually being empty.

-- Regards,
Denis Golovan

More information about the fpc-pascal mailing list