I spent a baffled hour or so last week trying to find a bug that I had suddenly inadvertently introduced into my code. The beastie was generating error messages that seemed to suggest something catastrophically wrong, up to and including internal compiler errors. Once I realised what I had done - changed an *argumentless *subroutine to a function - it was easy to put things right again. But I was left thinking that the compiler had not done a very good job of diagnosing and handling the error. Try and compile the following code:
integer function a
a = 2
return
end function a
and FTN95 (v5.01) will report as follows:
... : error 820 - 'A' found after FUNCTION where a comma was expected ... : error 491 - RETURN cannot be inside a PROGRAM block ... : error 778 - END FUNCTION found where END PROGRAM was expected ... : error 283 - A must appear in a type declaration because IMPLICIT NONE has been used
This collection of error messages strike me as unhelpful verging on misleading:
- why would the compiler expect a comma after the keyword FUNCTION?
Presumably it thinks the line is defining two integer variables named 'function' and 'a'. But then:
- why does it think this is a program block when it does not start with the keyword PROGRAM?
- similarly, why does it expect END PROGRAM without a matching PROGRAM?
What do others think?