[fpc-pascal] Variant record consistency
Gerhard Scholz
gs at g--s.de
Mon Aug 8 08:53:33 CEST 2016
I assume, my response was a bit unclear. If you code it like this, you
should get a runtime-error or compiler-error if the two variants are not
same-sized, and I assume, this is what you wanted.
----- Original Message -----
From: "Gerhard Scholz" <gs at g--s.de>
To: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
Sent: Sunday, August 07, 2016 8:00 PM
Subject: Re: [fpc-pascal] Variant record consistency
> if same size is necessary, I would do it like this:
>
> const
> topDataQword= 29;
> topNameChar= 231;
>
> type
> Tfnord1 = array[0..topDataQword] of qword ;
> Tfnord2 = record
> name: array[0..topNameChar] of char;
> inode: qword
> end ;
> Tfnord= record
> case boolean of
> false: (data: Tfnord1);
> true: (ni : Tfnord2)
> end;
>
> and, in the code:
> if sizeof(tfnord1) <> sizeof(tfnord2) then halt(4711);
>
> or, in the data
> type xxxxxxtest = array [ 1..ord(sizeof(tfnord1) = sizeof(tfnord2)) ] of
> boolean ;
>
> ----- Original Message -----
> From: "Mark Morgan Lloyd" <markMLl.fpc-pascal at telemetry.co.uk>
> To: <fpc-pascal at lists.freepascal.org>
> Sent: Sunday, August 07, 2016 6:11 PM
> Subject: [fpc-pascal] Variant record consistency
>
>
>> Given a declaration
>>
>> const
>> topDataQword= 29;
>> topNameChar= 231;
>>
>> type
>> Tfnord= record
>> case boolean of
>> false: (data: array[0..topDataQword] of qword);
>> true: (name: array[0..topNameChar] of char;
>> inode: qword) (* For recovery if name is
>> changed *)
>> end;
>>
>> is it possible to enforce a rule that the two record variants must be the
>> same size?
>>
>> --
>> Mark Morgan Lloyd
>> markMLl .AT. telemetry.co .DOT. uk
>>
>> [Opinions above are the author's, not those of his employers or
>> colleagues]
>> _______________________________________________
>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list