Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Error related to absent optional argument

$
0
0

The following code is a simplified version of another example posted by "Simon" on the Silverfrost Fortran Forum, see http://forums.silverfrost.com/viewtopic.php?p=18780 . My reading of the Fortran 2008 standard, section 12.5.2.12.3(1) indicates that the code is not conforming since the two elements of array j, which is not present, are referenced in Line-10. Gfortran 4.7 and 5.2 stop with a seg-fault on line-21. Sun Fortran 12.4 on Linux says " Attempting to use a missing optional dummy 'J' Location:  line 10 column 14 of 'pres0.f90'". With Intel Fortran 2015.2.164 and 16.0.0.109 on Linux the program completes execution, and the output was actually what "Simon" expected.

PROGRAM absent
!
 CALL s1 ()
!
CONTAINS
!
 SUBROUTINE s1 (j)
  INTEGER, INTENT(IN), OPTIONAL :: j(2)
!
 CALL s2 (j1=j(1),j2=j(2))
 END SUBROUTINE s1
!
 SUBROUTINE s2 (j1,j2)
  INTEGER, INTENT(IN), OPTIONAL :: j1, j2
  IF (PRESENT(j1)) THEN
     PRINT *, 'j1 = ',j1
  ELSE
     PRINT *, 'j1 N/A'
  END IF
  IF (PRESENT(j2)) THEN
     PRINT *, 'j2 = ',j2
  ELSE
     PRINT *, 'j2 N/A'
  END IF
 END SUBROUTINE s2
END PROGRAM absent

The program output with Intel Fortran, compiled with -C:

 j1 N/A
 j2 N/A

 


Viewing all articles
Browse latest Browse all 2583