Re: Read binary data file
~kurt wrote:
There is nothing wrong with simply writing
the C structure to a file, and reading it in the same way.
Nigel Wade wrote:
There is everything wrong with this. This is the fundamental problem. The amount
of padding which is used internally within a struct is undefined by the
language - it is entirely up to the compiler developer. If you write a struct
in binary both the data *and the padding* will be output together, all
intermingled. Further, since the amount of padding is at the discretion of the
compiler writers they are free to change the amount they use in any release of
their compiler. So you could quite easily find that an upgrade to the compiler
causes your code, which you say is perfectly acceptable, to break even on the
same hardware and OS.
A point which has been made several times in this thread.
In this case
the code, and not some specification, drives the format of the data - and
there
is *nothing* wrong with this.
Yes there is. Code which writes unspecified data to a binary file is bad code.
It will almost certainly break at some time in the future.
Most emphatically.
The lack of a need to share the data outside of
the application is what often drives the decision to use binary data in the
first place (why not take advantage of the efficiency binary files have to
offer).
But it is wise to know what is being written into your binary file so that you
can reliably read it back in. Otherwise it's reverse GIGO, it's GOGI - garbage
out, garbage in.
Another point which has been made several times in this thread, in various ways.
Of course, every once in a while an outside user decides they want to use this
data. Well, then they have a choice. Either generate it themselves, or
spend a few hours writing something that can read it in - not a big price
to pay.
But somewhat difficult if the original program's author didn't know what they
were writing into their binary files. I
Which is why we keep advising the OP (who seems to have lost interest in their
question) to determine exactly what that format they're using, then to code to
that specification. This point seems to have been lost repeatedly.
I would love for the OP to chime in and let us know that they've done this
step. How 'bout it, Windsor.Locks? Any luck with that analysis? What did
you find?
--
Lew