Incorrect Inline Variable Format May NOT Generate Errors

ID: Q72846

4.00 4.01 4.10 5.00 5.10 1.00 1.00a | 4.10 5.00 5.10 | 1.00 4.00

MS-DOS                              | OS/2           | WINDOWS NT
kbprg

The information in this article applies to:

SUMMARY

Using Microsoft FORTRAN, a program using a character variable for a FORMAT specifier on a READ or WRITE statement may not generate a run-time error even though the FORMAT specifier is incorrect. This may happen if the FORMAT specifier represented by the character variable is correct up to one edit descriptor past the edit descriptor needed by the I/O list of the corresponding READ or WRITE statement, even if the remainder of the FORMAT specifier is incorrect.

The errors that may be expected correspond to those available within Microsoft FORTRAN that indicate an invalid format descriptor.

MORE INFORMATION

The character variable is parsed as a FORMAT specifier only to the point required by the number of variables in the I/O list of the READ or WRITE statement using the FORMAT specifier. A run-time error will not be generated unless the number of variables in the I/O list causes the run- time routines to parse to the incorrect or syntactically invalid portion of the FORMAT specifier.

For example, in the program below, during the first WRITE statement, the run-time routine parses the format specifier string to obtain the first edit descriptor. It then matches the edit descriptor with the first variable in the WRITE statement. Since these match (an integer variable and an integer edit descriptor), the run-time routine goes back to the FORMAT specifier string to obtain the second edit descriptor. In parsing this edit descriptor and finding it valid, the run-time routine then attempts to match it with the next variable in the WRITE statement. As no second variable exists, the first variable is printed out according to the first FORMAT specifier, and the program continues on.

The difference with the second WRITE statement is that while matching the edit descriptors with the corresponding variables to be written out, the run-time routine attempts to parse the string one edit descriptor further than the first WRITE statement. This edit descriptor is incomplete, and the "F6988: unexpected end of format" error is generated.

       character*20 fmt
       integer i
       i=10
       fmt='(1x,i4,i4'
       write(*,fmt) i     ! prints out i, since the FORMAT is
                          ! correct up to the next edit descriptor
       write(*,fmt) i,i   !  generates run-time error F6988

       end

This program produces the following output:

10

     run-time error F6988: WRITE(CON)
     - unexpected end of format

Additional reference words: kbinf 1.00 5.00 5.10 KBCategory: kbprg KBSubcategory: FORTLngIss
Keywords          : kbFortranPS kbLangFortran 
Version           : 4.00 4.01 4.10 5.00 5.10 1.00 1.
Platform          : MS-DOS NT OS/2 WINDOWS

Last Reviewed: December 13, 1995