練習として、オプショナル引数を使ったサンプルプログラムを作った。
program ex call ex_sub( 1, z = 3 ) contains subroutine ex_sub( x, y, z ) implicit none !integer, intent( in ) :: x, y, z integer, optional :: x, y, z if ( .not. present( x ) ) x = 0 if ( .not. present( y ) ) y = 0 if ( .not. present( z ) ) z = 0 print *, x, y, z return end subroutine ex_sub end program ex
省略された引数の値を初期化したいので、引数を変更することを禁止するintentとは相性が悪いと思われる。