Reading Pascal-generated PACKED binary w/ C program 
Author Message
 Reading Pascal-generated PACKED binary w/ C program

Quote:

> Hope this is the right place!  :)

> I have need to read a binary containing Pascal packed records using the C
> language.

> 1) I have the packing rules that the Pascal compiler used, as well as the
> packed record declarations from the source code.

> 2) The original Pascal compiler used to generate the files is not available
> for me to use (it ran on a platform that is being retired).

     You should be able to build a similar "struct" structure in C that is
equivalent to the
packed binary record.  The only places you may have trouble are (a) subrage
types,
(b) sets, and (c) reals.

(a)  Many Pascal implementations use just enough bytes to cover the subrange.
Thus 0..200 would take one byte, while 0..1000 would take 2.  I have no idea how
ranges with negative numbers would be packed (again, possibly minimal number of
signed bytes).

(b)  Sets are usually represented as bits.  Take the size of the base type,
divide by 8 (bits per byte), and this is probably the size-in-bytes of the set
representation.

(c)  Real representation varies with the compiler and possible compile-time
switches.  For that matter, integer representation may be variable (16 or 32
bit).

     One clue to representation is to dump a data record and try to make sense of
the bits, given the known (Pascal) structure.  Then write a corresponding C
Struct, and you should be all set (except, of course, that you'd have to use C,
instead of A, I mean, Pascal).

Bob Schor
Pascal Enthusiast



Tue, 12 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Can FreePascal generate flat binary files?

2. Can Excel read a Pascal binary file?

3. Reading binary files in pascal

4. Reading binary files in PASCAL ??

5. reading a Unix Generated text file

6. How to do fast sequential binary read ?

7. reading binary with freepascal

8. problems reading binary file, and outputting to screen.

9. reading binary file and outputting to standard output (screen)

10. Binary field read/write

11. I need to read a binary file

12. problem reading 4-byte reals from binary file

 

 
Powered by phpBB® Forum Software