What is the implementation of sets used in pascal?

前端 未结 2 1146
失恋的感觉
失恋的感觉 2021-01-20 16:24

I want to know the actual implementation of the set type in pascal, provided by the language. Specially, I would like to know the one used in the freepascal runtime library,

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 16:48

    The Free Pascal language documentation is the "reference" guide, the rtl is the runtime guide. Compiler options and directives are in the programmers guide, see the $pack* links below.

    Sets are bitfields, differing in size depending on options. (e.g.$packset and $packenum ), to maximum size of 256 bits, 32 bytes (this is an old TP limit).

    IIRC in (obj)FPC mode, sets grow with wordsize, and in Delphi mode with byte sized granularity, but that is a bit x86 centric. The size=3 bytes is however not possible, and will be rounded up to 4.

    The lower bound is always 0, so a set of 8..10 is 2 bytes (0..15) even though it can only hold 3 values (8,9,10).

    Besides this there is also a little endian vs big endian issue. On big endian systems you can't access set fields alternately bytewise and wordwise. Afaik FPC mostly accesses them wordwise, but it is a while I ago that I last checked that.

提交回复
热议问题