Using binary data files
Conor O'Neill
conor at lion.inmos.co.uk
Thu Mar 28 00:57:50 AEST 1991
In article <1991Mar21.021023.25615 at athena.mit.edu> scs at adam.mit.edu writes:
>The moral: DON'T USE BINARY DATA FILES. (You'll say, "but we
>have to, for efficiency." Sure, and go ahead, but don't come
>crying to me :-) when you have problems -- and you will have
>problems.)
Binary data files are fine, AS LONG AS YOU SPECIFY THE FORMAT,
in the same way that if you use an ASCII file, you would say something
like "Ten decimal integers separated by spaces, on each line".
The problem is that many people `document' the format by supplying a
struct definition, and, of course, struct definitions are most definitely
_not_ portable.
A binary file specified as something like "Each 'record' is a list of 10
32-bit twos-complement integers, each stored least significant byte first"
is perfectly portable. On some machines, they could be read directly into
a struct. On others, simple reading and writing routines would be required.
But, of course, this would be in the machine-dependent part of your program,
together with all the other machine-dependent parts which would have
to be modified anyway when porting.
---
Conor O'Neill, Software Group, INMOS Ltd., UK.
UK: conor at inmos.co.uk US: conor at inmos.com
"It's state-of-the-art" "But it doesn't work!" "That is the state-of-the-art".
More information about the Comp.lang.c
mailing list