handling of exit status, bug or feature?

Hi,

I have one problem with programs compiled with the pgf90 compiler that I cannot find any references to in the documentation or in this forum.
The point is that I need to adapt my program to certain interface guidelines, and one of them is the ability to generate non-zero exit status when a problem occurs.

In fortran I am used to code this using the stop command, and would expect a command like ‘stop 132’ to exit my program, maybe print a message to stderr and then set the status environment variable to a value of 132, so this can easily be tested in scripts calling this program.
This procedure works for all fortran 90 compilers I know of, except for pgf90.

Now I don’t actually don’t know if this behaviour is required by the Fortran language standard, but even if it is not, it would be a very usefull addition for those who need it.

A few lines of sample code to demonstrate this on my linux machine:

cat teststop.F90
program teststop

print *,‘just a test print’
stop 132

end program teststop

pgf90 -o teststop teststop.F90
./teststop
just a test print
132
echo $status
0

For comparison, the ifort compiler behaves like this:

ifort -o teststop teststop.F90
./teststop
just a test print
132
echo $status
132

For reference, the versions used for this test:

pgf90 -V

pgf90 10.5-0 32-bit target on x86 Linux -tp penryn
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2010, STMicroelectronics, Inc. All Rights Reserved.

ifort -V
Intel® Fortran Compiler for applications running on IA-32, Version 10.1 Build 20071116 Package ID: l_fc_p_10.1.011
Copyright © 1985-2007 Intel Corporation. All rights reserved.

Best regards,

Jos.

Hi Jos.

The F2003 standard only states that the digit or string after the STOP should be printed upon termination. The F2008 standard does recommend that if the stop code is an integer, then the value should be used as the exit status, however, it does not require it.

Though, it does make sense to add and shouldn’t be too difficult. Hence I’ve added a feature request (TPR#17524). Though we’ll need to determine what the behavior should be if the stop-code is greater than 255 or is a string.

For now, you can simply add a call to the C exit routine to set the exit status. For example:

% cat test.F90 

program teststop
print *,'just a test print'
call exit(132)
end program teststop 

% pgfortran test.F90 ; a.out ; echo $status
 just a test print
132
% ifort test.F90 ; a.out ; echo $status
 just a test print
132

Thanks,
Mat

Hi Mat,

thanks for your reply, and for giving me this workaround.
I’ll see this new feature then in a future pgf90 version.

For integer numbers outside the valid range 0-255, the simplest thing probably is to issue a compiler error to warn the user.

Jos.

We have implemented this in the 13.9 release.

thanks,
dave