test64
Overview
test64 (code/tests/test64.c, authored by John Hughes Clarke in August 1992) is a system-architecture and compiler-portability diagnostic utility created when migrating the OMG software suite across 32-bit and 64-bit Unix/Linux platforms (such as SGI IRIX MIPS, Sun SPARC, DEC Alpha, and x86/x86_64 Linux).
When executed, test64 reports three critical platform properties:
- Compile-Time Endianness Macros (
INTELvs.MOTOROLA): Prints the integer values ofINTELandMOTOROLAdefined inswapio.hto verify whether byte-swapping routines (jswap_short,jswap_int,jswap_float) are configured for little-endian or big-endian host order. - C Primitive Type Sizes (
sizeof): Prints the byte widths (%ld) oflong int,int,short,float, anddoubleβspecifically checking whetherlong intis 4 bytes (ILP32) or 8 bytes (LP64on 64-bit Unix/Linux), which directly impacts binary header structs in OMG formats. - File Seeking &
ftellOffset Width: If an optional<inname>file is provided on the command line, opens the file, seeks toSEEK_END(fseek(infile, 0, SEEK_END)), and prints the resulting byte offset (ftell(infile)) as along int(%ld) to verify large-file support.
Syntax & CLI Options
test64 [-v] [-depth <val>] [<infile> [<outfile>]]
| Option | Description | Default |
|---|---|---|
<infile> | Optional input file path used to test fopen, fseek(infile, 0, SEEK_END), and ftell(infile). | None |
<outfile> | Optional second positional argument stored in outname (commented out in source). | Unused |
-v | Parsed on command line (no-op). | Unused |
-depth <val> | Consumes one following argument on the command line (no-op). | Unused |
Diagnostic Output Interpretation
Running test64 on a 64-bit Linux (LP64, little-endian x86_64) system produces:
INTEL 1 MOTOROLA 0
8 4 2 4 8
where the five sizeof integers correspond to:
| Position | Expression | 32-bit (ILP32) | 64-bit (LP64) |
|---|---|---|---|
| 1 | sizeof(long int) | 4 bytes | 8 bytes |
| 2 | sizeof(int) | 4 bytes | 4 bytes |
| 3 | sizeof(short) | 2 bytes | 2 bytes |
| 4 | sizeof(float) | 4 bytes | 4 bytes |
| 5 | sizeof(double) | 8 bytes | 8 bytes |
[!IMPORTANT] Because
sizeof(long int)changes from 4 bytes on 32-bit architectures to 8 bytes on 64-bit Linux (LP64), all fixed-width 32-bit integer fields in OMG binary file headers (.merged,.r4,.mos) must be declared asint(4 bytes) rather thanlong.test64was written specifically to verify these type sizes during compiler transitions.
Example Usage
# Check host endianness, data type byte widths, and file size of a .merged file
test64 survey_line_001.merged
Sample output:
INTEL 1 MOTOROLA 0
8 4 2 4 8
going to open survey_line_001.merged
opened going to seek 2
where I am 0
seeked
length 14582400