Mail Archives: djgpp/1999/08/12/12:02:28
sephiroth writes:
> I always get by this problem by specifically defining a short or a
> long. I think this is good practice.
The size of a short or long isn't any more specific than the
size of an int: these can vary depending on your compiler and
the type of machine you are working with. It is never correct
to make any assumptions about the size of data types, which
is why you should never read block data from a file directly
into a structure. To make your code portable, you need to
read each field as a series of individual bytes, and combine
them into whatever memory layout you want to use (this can
most easily be done by writing helper functions that read
values of 16 bits, 32 bits, etc). For an example of this in
action, take a look at the pcx.c file from Allegro.
Shawn Hargreaves.
- Raw text -