[fpc-pascal] Empty record inside another record ?

Daniël Mantione daniel.mantione at freepascal.org
Sat Feb 16 17:24:00 CET 2008



Op Fri, 15 Feb 2008, schreef Skybuck Flying:

> To me it seems like some kind of trick, to extend a record at runtime.
>
> The empty record field, functions as a sort of offset/label/pointer if yo=
u =

> will to the new fields that will will be extended to the record by simply =

> allocating more memory then the size of the record.
>
> Then this "label"/"field" can be used as a sort of offset, by typecasting=
 it =

> to some extension record type.
>
> Could be pretty handy, quite impressive trick.
>
> However, is it safe to use ?

Empty records are valid Pascal.

> I cannot find anything in the documentation about this ?

Nothing in the documentation says it is forbidden either. The reason =

it is not explicetely mentioned is because there exists a =

much better method, objects:

type  base_structure=3Dobject
         field1:byte;
       end;

       extended_structure=3Dobject(base_structure)
         field2:byte;
       end;

Dani=EBl


More information about the fpc-pascal mailing list