List-directed read error?

Gfortran and ifort both run this program but give different outputs when list-directed reading a real value into an integer variable. Is the program f2018-compliant? Are both compilers f2018-compliant?

program listdirected
  implicit none
  integer:: i = 42, ios
  character:: input*7 = '3.14159', msg*200
  read(input,*,iostat=ios,iomsg=msg) i
  if(ios /= 0) print*, trim(msg)
  print*, 'i = ',i
end program listdirected

The gfortran output:

Bad integer for item 1 in list input
 i =           42

The ifort output:

 i =  3

Both compilers are compliant. The standard says, “When the next effective item is of type integer, the value in the input record is interpreted as if an Iw edit descriptor with a suitable value of w were used.” What is “suitable” is implementation-dependent. Intel Fortran is more forgiving than the standard in that it allows free conversion among numeric types in list-directed input. The standard does not require a processor to diagnose this.

2 Likes

Thank you @sblionel. I had thought that reading an integer from ‘3.14159’ as 3 was treating a decimal point as a separator, which is not allowed.