As the title says, really.
Is there anything against not using stop, like this:
PROGRAM myprog
.
. < do stuff >
.
END PROGRAM myprog
rather than using an explicit stop, as in this:
PROGRAM myprog
.
. < do stuff >
.
STOP
END PROGRAM myprog
I see a lot of older fortran code that has a STOP
before the END PROGRAM
statment, but is it really needed there?
On our Cray machine, having a STOP
stament at the end of the program writes the string "STOP" to STDERR, which is a bit annoying...
STOP tells the computer to stop running the program. In principle STOP can appear anywhere in the program and there can be any number of them. END tells the compiler (i.e. the program that takes your FORTRAN source and converts it into machine code) that this is the end of a program unit for compilation.
The STOP statement terminates execution of the program.
Here is an example: the subroutine "division" takes an integer input value and iteratively divides it by a value that is the input value decremented by the number of steps-1. When such value reaches zero, a flag should be raised and the subroutine should be exited without performing the division by zero.
A statement consists of one or more key words, symbolic names, literal constants, and operators, with appropriate punctuation. In FORTRAN, no keywords are reserved in all contexts. Most statements begin with a keyword; the exceptions are the statement function and assignment statements.
The code
stop
end program
is redundant as far as the program return value is concerned in modern Fortran. A stop
with no integer or character stop-code should return a 0 exit code to the OS if exit codes are supported. If end program
is encountered the behavior is the same, returning 0 to the OS.
The difference arises in program output. As you've noted, stop
produces output. The standard (Fortran 2008 cl. 8.4) says
When an image is terminated by a STOP or ERROR STOP statement, its stop code, if any, is made available in a processor-dependent manner. If any exception (14) is signaling on that image, the processor shall issue a warning indicating which exceptions are signaling; this warning shall be on the unit identified by the named constant ERROR UNIT (13.8.2.8). It is recommended that the stop code is made available by formatted output to the same unit.
This recommends the stop-code be made available on standard error, which is where your STOP
output is coming from. If you had given a stop-code to stop
, it would have been output with STOP
. Additionally, if there are floating point exceptions signalling, you will get additional output on standard error detailing that condition.
If you don't desire the additional output from stop
and are not using it to return a non-zero error code to the OS, you can omit it from your program.
There is probably a historical reason for the stop
,end
ending of the main program, but my brief skimming of a FORTRAN66 manual did not enlighten me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With