It is pretty typical that aero engineers involved in CFD (computational fluid dynamics) need to ship around large (50-1000 MB) binary files between various big-endian and little-endian machines without having to reformat them.
Typically they generate files that are all big-endian using a compiler switch to avoid having to byte swap as well. So it'd be great to have a compiler switch that reversed the byte order of integers (2, 4, 8 byte) and floating point numbers (4, 8 byte) when they are read from or written to an unformatted file. For instance if you had an 4 byte int stored as an array of chars, you might swap it using this simple approach: for (i = 0; i < 4; i++ ) { swappedBytes[i] = bytes[3-i]; } or if you want to do the bit shifting thing, you do do it this way: return (((buf [ 3 ] & 0xff) << 24) | ((buf [ 2 ] & 0xff) << 16) | ((buf [ 1 ] & 0xff) << 8) | (buf [ 0 ] & 0xff)); (I grabbed this code from converToInt() in: gcc-4.1-20050909/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java) -- Summary: Add -byteswapio flag Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: enhancement Priority: P1 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rrr6399 at futuretek dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23815