For a small project (see Anecdotal Fortran... :-) - #8 by vmagnin), I need to write binary files in a little-endian order. In the following program, where I suppose the integers to be 4, 2 and 1 bytes (they are on my machine), I have successfully done what I want (but…):
program endian implicit none integer :: status integer(4) :: four integer(2) :: two integer(1) :: one four = 4 two = 2 one = 1 open(unit=1, file='endian.bin', access='stream', status='replace', & action='write', iostat=status) write(1, iostat=status) four, two, one close(1, iostat=status) end program endian
as you can see here:
$ gfortran -Wall fortran_endian.f90 && ./a.out && hexdump -C endian.bin 00000000 04 00 00 00 02 00 01 |.......| 00000007
Now, my question is: will my program write in little-endian on all machines? I have not found the term “little-endian” in the Fortran 2018 draft. And I therefore guess it is not guaranteed by the standard… Probably the endianness used in files is just the same as in RAM?