www.delorie.com/gnu/docs/gcc/g77_682.html   search  
Buy the book!

Using and Porting GNU Fortran

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] Weird READ

The statement


is equivalent to either




depending on which would be valid in context.

Specifically, if `N' is type INTEGER, `READ (FMT=(N))' would not be valid, because parentheses may not be used around `N', whereas they may around it in `READ (UNIT=(N))'.

Further, if `N' is type CHARACTER, the opposite is true---`READ (UNIT=(N))' is not valid, but `READ (FMT=(N))' is.

Strictly speaking, if anything follows


in the statement, whether the first lexeme after the close parenthese is a comma could be used to disambiguate the two cases, without looking at the type of `N', because the comma is required for the `READ (FMT=(N))' interpretation and disallowed for the `READ (UNIT=(N))' interpretation.

However, in practice, many Fortran compilers allow the comma for the `READ (UNIT=(N))' interpretation anyway (in that they generally allow a leading comma before an I/O list in an I/O statement), and much code takes advantage of this allowance.

(This is quite a reasonable allowance, since the juxtaposition of a comma-separated list immediately after an I/O control-specification list, which is also comma-separated, without an intervening comma, looks sufficiently "wrong" to programmers that they can't resist the itch to insert the comma. `READ (I, J), K, L' simply looks cleaner than `READ (I, J) K, L'.)

So, type-based disambiguation is needed unless strict adherence to the standard is always assumed, and we're not going to assume that.

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003