thanks for taking the time to respond, I really appreciate it.
The code is intended to read data from a file generated by a
fortran program and only ever will be run on windows machines.
I don't need a mega portable/robust app, just need a program
that will extract data for a particular version of the file.
Well, the first thing you need is a specification of how the
Fortran program wrote the data

.
Beyond that: you may have raised a case that I've generally
forgotten when talking about reading and writing binary data:
migration. You've got some old data, written in some format
(binary dump of the bytes in memory?), and you want to migrate
it to an established format for a new program. You're only
going to read the old data once, so worrying about what might
happen in some future version of the compiler, or some future
machine, is really irrelevant. In this case, if the code was
written using a simple binary dump of the bytes in memory, and
you can compile with something for which you're sure that the
binary images will be identical (far from obvious if it was
written in Fortran and you're reading it in C++), then the
simplest solution is to read the data into a "byte buffer" (an
std::vector< unsigned char > is what I usually use for this),
and memcpy the individual elements out of it. (This solves the
alignment problem, which may or may not be present, depending on
how the bytes were written.)
If it runs on windows 2k/xp/vista for most processors then
that's good enough for the time being. At this point I prefer
not to make life too difficult for myself and would prefer to
use the typecasting trick proposed by sebastian. Do you think
that it's safe "enough"?
If you're only reading the data once, maybe. You still have to
establish the format used by Fortran when the data was written,
and you have to worry about alignment issues (although that is
normally not a problem on an Intel).
As an added difficulty the fortran file is "record" oriented
not "stream" oriented (i don't know if I'm using the right
official terminology) which means that there's some
peculiarity about how I have to read the data; some records
contain only one int, others contain more. Since all the
records are 4*4 bytes long it means I have to skip around over
empty records/control info to read everything.
In other words, if I understand correctly, the file written by
Fortran has the following format:
-- It is a sequence of records.
-- Each record consists of an integers, containing the length
of the record, or some information allowing you to establish
the length (record type, etc.)
-- Any further information in the record takes the form of a
sequence of integers.
We still don't know what format the integers are in, of course,
except that they are four bytes, but that's a good start. The
probability that they aren't two's complement seems very, very
small in practice, so really, the only issue is byte order.
Still, you'll have to find out how they were written in the
Fortran program, and then find out what that means for the
format on disk (from the Fortran documentation).