Sun Studio 12: Fortran User's Guide

3.4.129 –xfilebyteorder=options

Support file sharing between little-endian and big-endian platforms.

The flag identifies the byte-order and byte-alignment of data on unformatted I/O files. options must specify any combination of the following, but at least one specification must be present:




max_align declares the maximum byte alignment for the target platform. Permitted values are 1, 2, 4, 8, and 16. The alignment applies to Fortran VAX structures and Fortran 95 derived types that use platform-dependent alignments for compatibility with C language structures.

little specifies a "little-endian" file on platforms where the maximum byte alignment is max_align. For example, little4 specifies a 32-bit x86 file, while little16 describes a 64-bit x86 file.

big specifies a "big-endian" file with a maximum alignment of max_align. For example, big8 describes a 32-bit SPARC file, while big16 describes a 64-bit SPARC file.

native specifies a "native" file with the same byte order and alignment used by the compiling processor platform. The following are assumed to be "native":


"native" corresponds to:  

32-bit SPARC  


64-bit SPARC  


32-bit x86 


64-bit x86 


spec must be a comma-separated list of the following:




%all refers to all files and logical units except those opened as "SCRATCH", or named explicitly elsewhere in the -xfilebyteorder flag. %all can only appear once.

unit refers to a specific Fortran unit number opened by the program.

filename refers to a specific Fortran file name opened by the program. Examples:

-xfilebyteorder=little8:%all,big16:20 Notes:

This option does not apply to files opened with STATUS="SCRATCH". I/O operations done on these files are always with the byte-order and byte-alignment of the native processor.

The first default, when -xfilebyteorder does not appear on the command line, is -xfilebyteorder=native:%all.

A file name or unit number can be declared only once in this option.

When -xfilebyteorder does appear on the command line, it must appear with at least one of the little, big, or native specifications.

Files not explicitly declared by this flag are assumed to be native files. For example, compiling with -xfilebyteorder=little4:zork.out declares zork.out to be a little-endian 32-bit x86 file with a 4-byte maximum data alignment. All other files in the program are native files.

When the byte-order specified for a file is the same as the native processor but a different alignment is specified, the appropriate padding will be used even though no byte swapping is done. For example, this would be the case when compiling with -m64 for 64-bit x86 platforms and -xfilebyteorder=little4:filename is specified.

The declared types in data records shared between big-endian and little-endian platforms must have the same sizes. For example, a file produced by a SPARC executable compiled with -xtypemap=integer:64,real:64,double:128 cannot be read by an x86 executable compiled with -xtypemap=integer:64,real:64,double:64 since the default double precision data types will have different sizes.

Note that unformatted files containing REAL*16 data cannot be used on x86 platforms, which do not support REAL*16.

An I/O operation with an entire UNION/MAP data object on a file specified as non-native will result in a runtime I/O error. You can only execute I/O operations using the individual members of the MAP (and not an entire VAX record containing the UNION/MAP) on non-native files.