[Info-vax] Fortran Exit Codes

Arne Vajhøj arne at vajhoej.dk
Sun Feb 25 19:37:55 EST 2024


On 2/25/2024 7:16 PM, Lawrence D'Oliveiro wrote:
> Just looking at the Fortran 2018 spec, section 11.4, “STOP and ERROR
> STOP statements”. Paragraph 2 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 the stop-code is an integer, it is recommended that the
>      value be used as the process exit status, if the processor
>      supports that concept. If the stop-code in a STOP statement is of
>      type character or does not appear, or if an end-program-stmt is
>      executed, it is recommended that the value zero be supplied as the
>      process exit status, if the processor supports that concept. If
>      the stop-code in an ERROR STOP statement is of type character or
>      does not appear, it is recommended that a processor-dependent
>      nonzero value be supplied as the process exit status, if the
>      processor supports that concept.
> 
> But on VMS, the usual success status code is 1, with other odd values
> indicating varying degrees of success, while even values (including
> zero) indicate warnings or errors. So how does that work?

1) "recommended" is a pretty vague term.

2) VMS Fortran is not Fortran 2018 - it is Fortran 95.

3) Fortran 95 spec says:

<quote>
8.4 STOP statement
R840 stop-stmt is STOP [ stop-code ]
R841 stop-code is scalar-char-constant
or digit [ digit [ digit [ digit [ digit ] ] ] ]
Constraint: scalar-char-constant shall be of type default character.
Execution of a STOP statement causes termination of execution of the 
program. At the time of
termination, the stop code, if any, is available in a 
processor-dependent manner. Leading zero
digits in the stop code are not significant.
</quote>

4) Reality is pretty simple:

$ type Z1.for
       program z1
       end
$ for Z1
$ link Z1
$ run Z1
$ sh symb $status
   $STATUS == "%X00000001"
$ type Z2.for
       program z2
       stop
       end
$ for Z2
$ link Z2
$ run Z2
$ sh symb $status
   $STATUS == "%X00000001"
$ type Z3.for
       program z3
       stop 44
       end
$ for Z3
$ link Z3
$ run Z3
44
$ sh symb $status
   $STATUS == "%X00000001"
$ type Z4.for
       program z4
       stop 'Bingo'
       end
$ for Z4
$ link Z4
$ run Z4
Bingo
$ sh symb $status
   $STATUS == "%X00000001"
$ type Z5.for
       program z5
       call sys$exit(%val(44))
       end
$ for Z5
$ link Z5
$ run Z5
%SYSTEM-F-ABORT, abort
$ sh symb $status
   $STATUS == "%X0000002C"

Arne




More information about the Info-vax mailing list