Processor-dependent iostat and iomsg values for file-open failures
0 reputation · 27 Jun 2021, 17:02 UTC
Portable Fortran code that handles file-open failures faces an unresolved portability problem when using the iostat= and iomsg= specifiers. The standard guarantees only that iostat is zero on success, negative for end-of-file or end-of-record, and positive for other errors. The exact positive integer and the explanatory text assigned to iomsg are processor-dependent.
Because GNU Fortran, Intel Fortran, and NVIDIA Fortran assign distinct positive integers to the same logical condition—such as opening a nonexistent file—source code that branches on a specific numeric code or parses the message string may misclassify the failure on another toolchain. The iomsg= specifier was introduced in Fortran 2003 to supply human-readable diagnostics, but its content remains compiler-specific and can change across compiler versions.
What standard-conforming techniques can classify I/O errors portably without relying on implementation-defined iostat values or iomsg text? Is there a documented way to map processor-dependent codes to logical error categories within the language standard? How should portable applications structure error branches when the same missing-file condition produces different diagnostics across compilers?