[fpc-pascal] Variant record consistency

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Mon Aug 8 09:48:06 CEST 2016


Tomas Hajny wrote:
> On Sun, August 7, 2016 18:11, Mark Morgan Lloyd wrote:

>> is it possible to enforce a rule that the two record variants must be
>> the same size?
> 
> What would the rule supposedly do? As far as I know, all the variants take
> the size of the largest one technically (in memory). Do you mean that the
> compiler should warn if their declared size differs?

Noting obviously Jonas's and Gerhard's comments.

I was wondering whether the compiler could warn if it found that it had 
to insert padding since one or other of the variants didn't reach the 
end of the overall record, the size of which is obviously determined by 
the largest variant. Obviously, as Gerhard points out, there's ways 
round it, and I've already got a number of mandatory size checks (i.e. 
not just assertions) to catch things that smell unusual.

Area of application in this case is laying out a file structure to 
support a mainframe emulator, where the guest filesystem has no 
consistency checks so as much as possible needs to be done by the host. 
However similar requirements also apply wherever a data structure needs 
to overlay an existing file format or structure in memory.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list