Fortran 2003 / 2008: Elegant default arguments?
In fortran, we can define default arguments. However, if an optional argument is not present, it can also not be set. When using arguments as keyword arguments with default values, this leads to awkward constructs like PROGRAM PDEFAULT CALL SUB CALL SUB(3) CONTAINS SUBROUTINE SUB(VAL) INTEGER, OPTIONAL :: VAL INTEGER :: AVAL ! short for "actual val" IF(PRESENT(VAL)) THEN AVAL = VAL ELSE AVAL = -1 ! default value END IF WRITE(*,'("AVAL is ", I0)') AVAL END SUBROUTINE SUB END PROGRAM PDEFAULT Personally, I often ran into the problem of accidentially typing VAL instead of AVAL , i.e. the