Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-04

Packed array of boolean

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Walker, David

We're in the process of migrating an *OLD* (25+ years) application from Oregon Pascal / SCO Unix to Free Pascal (2.2.0) / SuSE Linux Enterprise. This involves at least 300,000 code lines.

The problem we've encountered is with "packed array of boolean". The compiler seems to "pack" booleans 1 per byte, whereas our old compiler packed them one per bit, into the smallest size possible. This presents a problem, because the records in our 135 disk files (per site) store bit arrays in this manner. We're trying to avoid having to do conversions on these files, as there are 600+ sites affected, and some of the files at these sites contain in excess of 1 million records.

I understand there is a TBits I could possibly use. The problem there is two-fold:

1) None of the other code is even remotely object-oriented. This is an old-fashioned procedural program, with a character interface, no mouse, no doohickeys, no popup anything. This might not be a problem but for the next point:
2) the TBits doesn't appear to have a way to write the contents of its bit array anywhere. I can test and set bits, but that appears to be about all. I can't save the bits once I've set/cleared them.

In reference to point 2 above, I attempted to write a descendant of TBits with the necessary Write method, but FBits (the actual bit array) is declared private in TBits, so I can't access it. IMO it should have been declared protected. Unfortunately, rewriting the existing TBits is not within the scope of the present project.

So, am I overlooking something in TBits, or am I reduced to writing the bit-twiddling routines myself? Or is there another approach someone can suggest?

TIA

Dave Walker

Reply by email

Florian Klaempfl
to Walker, David

Walker, David schrieb:

Please use fpc-pascal for user questions.

The problem we've encountered is with "packed array of boolean". The compiler seems to "pack" booleans 1 per byte, whereas our old compiler packed them one per bit, into the smallest size possible.

[...]

So, am I overlooking something in TBits, or am I reduced to writing the bit-twiddling routines myself? Or is there another approach someone can suggest?

Use bitpacked instead of packed.

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 7 lines
Walker, David schrieb: > So, am I overlooking something in TBits, or am I reduced to writing > the bit-twiddling routines myself? Or is there another approach > someone can suggest? Use bitpacked instead of packed.

Note that FPC's bitpacked is not necessarily the same bitpacked as what the old compiler used (although there aren't that many choices for 1-bit values, obviously), and that the internal format of bitpacked arrays/records is not guaranteed to remain compatible between different FPC versions either (and additionally it is *guaranteed* to be incompatible between CPUs with a different endianess).

Jonas

Reply by email

Michael Schnell
to Jonas Maebe

Using implementation dependent internal representations (such as Bit position, endieness, size of "integer", pointers etc.) for communication via files or network is extremely bad style.

But of course he can't help it in that case. If a decent documentation is provided how the bits in the file are to be interpreted, any format is OK.

Thus I suggest using a dedicated function to read and write the file and internally use the most appropriate internal representation (Word or Byte Bool).

-Michael

Reply by email