Endianess
Toon Moene
toon@moene.indiv.nluug.nl
Thu Aug 13 05:47:00 GMT 1998
> This really sounds like a FAQ item to me, to clear this
> up once and for all...
[ Good points snipped, thanks ]
> If your data file contains only an unstructures stream
> of 32 bit integers, you can use the following utility
> program to reverse byte ordering:
This is, unfortunately, not true in general. A Fortran unformatted
sequential file *as generated by the f2c run time library* (and
hence by g77, whether part of egcs or combined with gcc) has the
following structure:
#-of-bytes-in-record, contents-of-record, #-of-bytes-in-previous-record
...
all concatenated in binary "words".
The problematic thing is the #-of-bytes-in-record. On some systems
this is a 32-bit integer, on some (like the Alpha) it is a 64-bit
integer [An unfortunate situation we're not going to resolve without
breaking backwards compatibility].
Hence, on Alpha, one can only reverse-endian a file with 64-bit
INTEGERs and REALs in the simple way shown, and then s/he has to
change the declaration of N1 and N2 thusly:
INTEGER*8 N1, N2
and open the files with the following statement:
OPEN(1,FORM='UNFORMATTED',ACCESS='DIRECT',RECL=8)
OPEN(2,FORM='UNFORMATTED',ACCESS='DIRECT',RECL=8)
Hope this clarifies,
Toon.
More information about the Gcc
mailing list