[fpc-pascal] How to translate this C header struct to Pascal
Jeff Wormsley
daworm10 at comcast.net
Fri Oct 23 23:27:45 CEST 2009
Graeme Geldenhuys wrote:
> The first item is 31bit and the second item is 1 bit. Does FPC support
> a record structure that can define bit level sizes?
>
I've done this kind of thing quite a bit in the past. Usually, I define
a "raw" version and a "clean" version, and write two routines to convert
back and forth. I read into the raw version, convert to the clean one,
use that in my application, then if I have to write it back, convert the
clean back to raw and write it out. I've been Windows only, but taking
into account Jonas' advice, you could make converter versions for each
ABI and ifdef them appropriately, and that would be located in one place
only, not strewn about your code everywhere you needed to access that
data. Its a little bit more work, but it only has to be done once each
way, and when I'm actually using the data, it saves a ton of mucking
about in the middle.
Lately, I've taken to wrapping such data into objects, and using the
getters and setters to handle getting things from and putting things
into the right bits, and only having the raw storage.
Of course, if you only need it once, it really doesn't matter where or
how you convert it.
Jeff.
--
I haven't smoked for 3 years, 2 months and 6 days, saving $5,236.88 and
not smoking 34,912.58 cigarettes.
More information about the fpc-pascal
mailing list