On Mon, 10 Nov 1997 18:54:57 -0500 (EST), Orlando Llanes wrote:
Is there anything in C that corresponds to packed records in Pascal?
Got me on that one :( Although I am very familiar with the types, type definitions, and I haven't seen anything really about packing the records like in Pascal. I could be wrong tho, if there is something, it's one of those deep dark secrets of C :P
Well, it won't be totally analogous to a packed record in Pascal, but you can of course define bit fields for variables. The C standard also allows padding by putting in x # of bits assigned to an unnamed field in order to fill out a byte or word. Also, a bit width of 0 will force alignment on the next word boundry. {See the last section in Chapter 6 of K&R} So I think you could simulate packed records but you would have to do it by manually setting integers to specific bit-widths. In fact, K&R refers to bit-fields as a method to 'pack several objects into a machine word.'
However there are a lot of caveats, like you can only use integer types, and the behavior if a field crosses a word boundry is implementation defined. So it would take a lot of work to simulate anything but the simplest Packed Pascal records--although I lost where the discussion began so I don't know for what reason you want to pack things in C.
-Kevin -- Kevin A. Foss --- kfoss@mint.net --