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,
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.
According to this explanation, Pascal internally represents sets as bit strings. However, the article apparently does not refer to a specific implementation of Pascal. In this documentation, it is also stated that bitstrings are used for representation. More precisely, this documentation explicitly mentions 32 bytes for storage of a set.