The proposed Fortran 202x standard raised the individual line limit to 10000 characters, with unlimited continuation lines, and a maximum statement length of a million characters. These are stated as "hard limits" but some compilers allow going beyond 10000 characters in a line or even a million characters in a line. For example LLVMFlang is explicitly designed to not have a particular character limit per line, while even today's HPC may default to a Gfortran older than 14 that has a default Fortran source code line length maximum of 132 characters, which is too short for say generated source code containing a data path on a networked HPC drive.
It's important to be cognizant of the maximum Fortran line length across compilers as developer laptops often default to a recent Flang or Gfortran that both have effectively unlimited line length.
The maximum line length we experienced with no options follows.
| Compiler | Maximum Line Length |
|---|---|
| gfortran 8.5.0 | 132 |
| gfortran 9.3.0 | 132 |
| gfortran 10.2.0 | 132 |
| gfortran 11.2.0 | 132 |
| gfortran 12.2.0 | 132 |
| gfortran 13.2.0 | 132 |
| gfortran 14.3.0 | 10000 |
| gfortran 15.2.0 | 10000 |
| gfortran 16.2.0 | 10000 |
| NVHPC SDK 23.5 | 1000 |
| NVHPC SDK 25.5 | 1000 |
| NVHPC SDK 26.5 | 1000 |
| IntelLLVM ifx 2023.1 | 7196 |
| IntelLLVM ifx 2024.0 | 7196 |
| IntelLLVM ifx 2026.1 | 7196 |
| LLVMFlang 22.1.8 | > 1,000,000 |
cmake -B buildAs usual, if desired specify compiler in the above command with -DCMAKE_Fortran_COMPILER=<compiler>.
Set the character line length limit by -DN=<value>.
Examples:
cmake -Bbuild -DCMAKE_Fortran_COMPILER=gfortran -DN=10001
-- Try to compile source with line length 10001
-- Try to compile source with line length 10001 - FAILcmake -Bbuild -DCMAKE_Fortran_COMPILER=gfortran -DN=10001 -DCMAKE_Fortran_FLAGS=-ffree-line-length-none
-- Try to compile source with line length 10001
-- Try to compile source with line length 10001 - OKFor Gfortran only, the maximum line length can be arbitrarily set, which we optionally enable with -DM=<value> like:
cmake -Bbuild -DCMAKE_Fortran_COMPILER=gfortran -DN=133 -DM=132
# intentionally set N greater than M to demonstrate failureThe "compiler.cmake" file example shows how one can manipulate Fortran source code line limits.
Gfortran:
Error: Unterminated character constant beginning at (1)
Intel oneAPI ifx:
catastrophic error: Token too long
NVHPC nvfortran:
NVFORTRAN-F-0923-String too long
Flang: didn't have a practical line length limit.