This situation, where Fortran doesn't check that you are using functions in the way that they are declared, is a major problem with Fortran 77. As programs get bigger and bigger, it becomes very likely that a programmer will make such a mistake. To make matters worse, finding a problem like this in a large program with no help from Fortran can be quite difficult.
Most modern languages do this kind of checking and warn programmers when they make this kind of mistake. Standard Fortran 77, with its roots in the 1950's, does not. Some implementations of Fortran go beyond the standard and provide inter-function type checking. The version on this machine, unfortunately, does not.
Fortunately, there is a program, separate from the Fortran compiler, that will do inter-function type checking even though the compiler will not. You can run this program, much like you do the compiler, by pulling down the Compile menu in Emacs and selecting the Check This File... option. When you do this, Fortran will display the command that it intends to run at the bottom of the window. It should be:
ftnchek types.f
You should type the Enter key to confirm that you want to run this command. What happens when you do?
Experiment with this file-checking program by going back through the modifications that you made to ``types.f'' earlier in this lesson. Try giving ADD three REAL arguments, two integer arguments, and finally two REAL arguments.
The checking program will warn you about many other potential problems as well. In addition to syntax errors, it will warn you about such things as using a variable before you've given it a value. You should get into the habit of checking your program and getting rid of all of the reported errors before compiling and running it. We guarantee that this will save you many hours of frustration this quarter!
Hamlet Project