[fpc-devel] Freepascal in microcontrollers
jonas.maebe at elis.ugent.be
Wed Feb 27 23:21:16 CET 2008
On 27 Feb 2008, at 22:46, Daniël Mantione wrote:
> There is no reason why bitpacked records should be any different
> from packed records: They should internally consistent. Therefore,
> the packing behaviour should be known, documented, and therefore
> usable for binary use.
They are already very different from regular packed records due to the
fact that their structure is completely different on little and big
endian systems (they are not byte swapped, but "bit swapped").
Locking the compiler into a particular implementation by documenting
and supporting the implementation details mainly lead to trouble (and
lack of optimization opportunities) later due to the legacy balast it
causes. And don't worry: even without documenting and supporting it,
people will still figure it out (well, it's documented by example in
the source code's comments, so that's not that hard), still depend on
the layout, and still file bugs if it changes for some reason.
And as Vinzent noted, simply making something "bitpacked" does not
make it suited for binary interfacing. You need more control over the
layout if you want to really use it. Bitpacked records are simply not
fit for defining a particular layout (let alone access patterns:
writing to a bitfield may involve loading the containing and several
surrounding bytes, sometimes more than once in the generic
implementation, and that's certainly not something you want to happen
when accessing hardware).
> In other words, if there will be ever differences as to target
> platforms, this has to happen only under $packrecords C, or an
> equivalent directive for bitpacked records.
There is no equivalent directive for bitpacked records, and supporting
C-style bitpacking is impossible with regular Pascal syntax ("char c:
1" and "int c:1" are often laid out differently in C depending on the
previous fields, but there is no way to express this difference using
plain Pascal; you need extra attributes -- not to mention that those
packing rules are often quite hairy, and it would be a mess to
implement them all).
More information about the fpc-devel