Valid Code Question

Jerry DeLisle jvdelisle@verizon.net
Sun Oct 30 09:17:00 GMT 2005


Hi All,

I am putting together a test case for pr24584.  I noticed that ifort rejects 
this at the read statement at compile time.  gfortran compiles it fine but gives 
a run time error message on the read.  If I take 'var' out of the read ifort 
accepts this and it runs fine.  Similarly it runs OK with gfortran with the 
patch listed in the pr (attached).  However, the second program listed below is 
also rejected by ifort, but gfortran accepts it and runs it fine.  Can someone 
give me an interpretation of what is and is not valid code in these cases.

! pr24584, segfault on namelist reading an empty string
       implicit none
       character*20   temp
       character(len=10) var
       namelist /input/ var
       var = 'Howdy'
       open(unit=7, status="scratch")
       temp = '   var='''''  ! var='' in the file
       write(7,'(A6)') '&INPUT'
       write(7,'(A10)') temp
       write(7,'(A1)') '/'
       rewind(7)
       read(7,NML=input) var ! Comment out var and this runs OK
       close(7)
       if (var.ne.'') call abort
       end
-----------------------------------------
         PROGRAM foo
         IMPLICIT NONE
         CHARACTER(len=10) var
         CHARACTER(len=10) sname
         NAMELIST /input/ var
         sname = 'howdy'
         WRITE(*,*) sname, "<<<"
         OPEN(unit=1,file="input.tmp",delim='apostrophe',status='unknown')
         READ(1,NML=input) var  ! This runs fine with var here
         CLOSE(1)
         WRITE(*,*) var
         OPEN(unit=1,file="toto.tmp")
         READ(1,*) sname
         CLOSE(1)
         WRITE(*,*) sname, "<<<"

         END PROGRAM foo

$cat input.tmp
&INPUT
    var=''
/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list_read.diff
Type: text/x-patch
Size: 783 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20051030/b6990327/attachment.bin>


More information about the Fortran mailing list