[fpc-devel] Record types with unbounded trailing data
Michael Van Canneyt
michael at freepascal.org
Mon Jun 24 06:41:24 CEST 2019
On Mon, 24 Jun 2019, J. Gareth Moreton wrote:
> Hi everyone,
> So after a problem over at https://bugs.freepascal.org/view.php?id=35753
> that led to a change of https://bugs.freepascal.org/view.php?id=35671 ,
> it became apparent that there may need to be better support for
> unbounded arrays in record types - not open arrays, but unbounded ones.
> It's a lot to think about for sure, and is probably overengineering a
> solution to a very niche problem (I personally can't think of where one
> would use such constructs instead of something with a fixed-size array
> or just having the header and open array stored separarely), but is it
> worth discussing?
No. This *really* is overengineering.
If you declare what is clearly a dummy structure, then tricks will be needed.
Disabling range checks on such constructs and warnings is the only sensible thing to do.
If you want to get rid of warnings, define it as
LOGPALETTE = record
palVersion : WORD;
palNumEntries : WORD;
palPalEntry : array[0..(MAXINT div sizeof(PALETTEENTRY)] of PALETTEENTRY;
Since you will always work through a getmem'ed memory block & pointer anyway, and
all bets are off in that case. There is simply no point in letting the
compiler check anything extra since the construct is by definition uncheckable.
More information about the fpc-devel