Chapter 39 — Key Takeaways (Fortran 2023 and Beyond)
A one-page reference to what Fortran 2023 shipped, how the language evolves, the modern ecosystem, and what is coming — with an honest "usable today?" column throughout, because that is this chapter's whole discipline.
Fortran 2023 features at a glance
| Feature | Syntax (illustrative) | What it does | Usable today? |
|---|---|---|---|
| Conditional expression | y = ( cond ? a : b ) |
Inline choice; evaluates only the taken branch | Landing unevenly — check compiler; keep an if/merge fallback |
| Enumeration type | (new distinct type; verify exact spelling) | A named, compiler-checked set of values | Thin support — use integer, parameter for now |
typeof / classof |
typeof(x) :: y |
Declare "same type as x" without naming it |
Mostly not yet in common gfortran |
| Degree trig | sind(30.0_dp) → 0.5 |
Trig in degrees (also cosd,tand,asind,atand,atan2d) |
Yes on recent gfortran; use -std=f2023 |
| Longer lines / names | — | Relaxed source-size limits (line ~132 → ~10,000 chars, as reported) | Increasingly; harmless if unused |
| Better C interop | — | Smoother Fortran↔C strings / interoperable types | Partial — verify the specific helper |
do concurrent … reduce |
do concurrent (i=1:n) reduce(+:s) |
Standard parallel reduction (CPU vectorize / GPU offload) | Uneven; confirm your compiler |
The one rule to internalize: conditional expression ≠ merge
! merge is a FUNCTION -> evaluates BOTH values, then chooses.
y = merge( x/denom, 0.0_dp, denom /= 0.0_dp ) ! x/denom runs even when denom == 0 (BUG as a guard)
! conditional expression -> evaluates ONLY the selected value (short-circuits).
y = ( denom /= 0.0_dp ? x/denom : 0.0_dp ) ! Fortran 2023; needs a recent compiler
- Use
mergeonly when both branches are always safe to compute. - Need short-circuiting? Use an
if/elsetoday, a conditional expression once 2023 lands.
How the language evolves
| Body | Role |
|---|---|
| WG5 (ISO/IEC JTC1/SC22/WG5) | International working group — sets direction, scope, schedule of each revision |
| J3 (US committee; was ANSI X3J3) | Detailed technical drafting; processes feature papers, votes them in |
- Cadence: roughly every 5 years — 2003, 2008/10, 2018, 2023, next in development.
- The standard is
ISO/IEC 1539-1; the 2023 edition isISO/IEC 1539-1:2023. - Backward compatibility is near-total: tired features are marked obsolescent, rarely deleted — which
is why 1970s
COMMON/fixed-form code still compiles. Evolution without breakage. - Publication ≠ availability: each compiler implements on its own schedule. Always check support.
The fortran-lang ecosystem (met properly in Chapter 16)
| Tool | What it is | One-liner |
|---|---|---|
| fpm | Fortran Package Manager | fpm build / fpm run; derives module order; git deps in fpm.toml |
| stdlib | Community standard library | The "batteries" (stats, sorting, strings); a dependency, not built-in |
| Playground | Browser Fortran runner | Run Fortran on a web page, nothing installed (powered by LFortran) |
| LFortran | Interactive LLVM compiler | Runs Fortran statement by statement (REPL/notebook); still maturing |
| LLVM Flang | New production LLVM compiler | Maturing alongside gfortran and the vendor compilers |
LFortran (first-defined here): an LLVM-based modern Fortran compiler that can also run Fortran interactively and power the browser playground — best for exploring/teaching today, not yet a drop-in for large production codes.
Where it's heading (proposed / coming — NOT shipped)
- Generics (the big one): parametric polymorphism — one algorithm/type over any type, compile-time checked, no dispatch cost. In development for the next revision. Complements Chapter 10's OOP.
- Better GPU support through the standard:
do concurrentoffload (e.g. nvfortran already), strengthened by 2023'sreduce. Goal: portable performance without vendor directives (Chapter 35). - Coarrays maturing: compilers finishing standardized features (e.g.
teams, weak in gfortran today). - Interop & tooling: smoother C boundary, LLVM Flang/LFortran maturing, growing stdlib, better
fortls.
Honesty rule: "Fortran 2023 added conditional expressions and degree trig" is a fact; "Fortran will have generics and seamless GPU offload" is a forecast. Keep them apart — in your code and your claims.
Numbers & names worth memorizing
sind(30)=0.5,sind(45)≈0.70711,sind(60)≈0.86603,sind(90)=1,sind(0)=sind(180)=0.- 2023 = ISO/IEC 1539-1:2023. Revision cadence ≈ 5 years.
- Committees: WG5 (ISO, steers) and J3 (US, drafts).
Compile flags introduced
-std=f2023— request Fortran 2023 semantics (needs a recent gfortran; older gfortran rejects the flag).
The heat-solver piece added this chapter
A Fortran 2023 refresh (optional): the hot edge initialized with a smooth half-sine profile via sind
(no pi/180), tried in LFortran / the Playground. Portable fallback (sin(x*pi/180)) kept as the default so
the solver still builds everywhere. For nx=5, t_hot=100: edge = [0, 70.711, 100, 70.711, 0].
(code/project-checkpoint.f90.)