Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exit code with Fortran 90

275 views
Skip to first unread message

Andrea Francia

unread,
Jan 30, 2008, 7:12:45 AM1/30/08
to
If I use the istruction
stop n
where n is a integer I found that the program terminate with n as exit
code.

I see that this happen compiling when I use the GNU Fortran compiler
(gfortran).

Is this behaviour standard, or it is a special behaviour of gfortran?

Dan Nagle

unread,
Jan 30, 2008, 7:34:05 AM1/30/08
to
Hello,

On 2008-01-30 07:12:45 -0500, Andrea Francia
<afra...@galielianplus.dot_it> said:

This behavior is unspecified by the f90/95/2003 standard.
These standards have no idea what an exit code is,
nor what a process is, and so on.

It is a recommendation, with caveats, in the f08 draft.

--

Cheers!

Dan Nagle

Joseph Huber

unread,
Jan 30, 2008, 7:43:05 AM1/30/08
to

The standard only says:

"...the stop code, if any, is available in a processor-dependent manner."

And I know at least one implementation (VMS DEC/HP Fortran) which
just displays the code (or string), and does not pass it to program exit
status.

--

Joseph Huber - http://www.huber-joseph.de

Gary Scott

unread,
Jan 30, 2008, 8:20:59 AM1/30/08
to
Not a very desirable implementation. it is quite useful when
implemented as an exit code that can be passed to other process/command
interpreters.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford

Walter Spector

unread,
Jan 30, 2008, 9:48:17 AM1/30/08
to

As Dan says, it is not required by the Fortran Standard per se.
However the POSIX Fortran Binding (1003.9-1992) does specify this
behavior (for small integer values.) As desirable as the feature
is, some compilers do it and some don't.

W.

John Harper

unread,
Jan 30, 2008, 3:58:22 PM1/30/08
to
In article <13q13hi...@corp.supernews.com>,

Even writing the code in octal is standard-conforming, e.g. NAG f95:

mahoe{~/Jfh} % cat stop666.f90
PRINT *,'Next statement is STOP',666
STOP 666
END
mahoe{~/Jfh} % nagf95 stop666.f90 ; ./a.out
Next statement is STOP 666
STOP: 1232
mahoe{~/Jfh} %

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5662 fax (+64)(4)463 5045

MDAru...@gmail.com

unread,
Feb 7, 2008, 12:12:52 AM2/7/08
to
On Jan 30, 5:12 pm, Andrea Francia <afran...@galielianplus.dot_it>
wrote:

hi Thanks dude . because of ur instruction "stop n" i cleared one of
the requirements in my proj.I think this is a standard command . I am
using Visual Fortran 6.6 and it shows the same behaviour.

Richard Maine

unread,
Feb 7, 2008, 1:49:26 AM2/7/08
to
<MDAru...@gmail.com> wrote:

> because of ur instruction "stop n" i cleared one of
> the requirements in my proj.I think this is a standard command . I am
> using Visual Fortran 6.6 and it shows the same behaviour.

The statement (not "command", by the way)

stop <n>

is indeed standard syntactically. However, as several people have noted,
the current Fortran standard does *NOT* specify that it has anything to
do with a program exit code. Dan, who first mentioned that in this
thread, happens to be the chair of the standards committee. He does know
at least a little about the subject. (Hi, Dan.)

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain

Andrea Francia

unread,
Feb 11, 2008, 7:11:44 AM2/11/08
to
Gary Scott wrote:
> Joseph Huber wrote:
...

> Not a very desirable implementation. it is quite useful when
> implemented as an exit code that can be passed to other process/command
> interpreters.
This is exactly what I need to do. I have a Java program that runs
Fortran executables.
I need a way to pass the information about the succesful termination
from Fortran to java program.

Gary Scott

unread,
Feb 11, 2008, 8:28:22 AM2/11/08
to

Yes, that is a common usage. I do it all the time. If your compiler
doesn't support it 1) complain to the vendor, 2) use a file, pipes, DDE,
or some other method to pass the exit code.

Andrea Francia

unread,
Feb 11, 2008, 10:14:57 AM2/11/08
to
Thanks everyone for the replies, now I know that this behaviour is not
part of the Fortran 95 standard, but it is part of the 1003.9-1992
standard and may be not avaialable on each Fortran 95 implementation.

Craig Dedo

unread,
Feb 11, 2008, 6:36:59 PM2/11/08
to
"Andrea Francia" <afrancia@galielianplus._remove_it> wrote in message
news:47b06672$0$4787$4faf...@reader4.news.tin.it...

Sending the stop code to the OS as an exit status is not now part of the
Fortran standard.

However, Fortran 2008 will include an enhanced STOP statement. Two of the
enhancements include displaying the stop code on ERROR_UNIT and using it as the
process exit status, if the processor has such a concept. The details are in J3
paper 05-231r4.

--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cd...@wi.rr.com> or <cr...@ctdedo.com>

Gary Scott

unread,
Feb 11, 2008, 9:30:34 PM2/11/08
to
Craig Dedo wrote:
> "Andrea Francia" <afrancia@galielianplus._remove_it> wrote in message
> news:47b06672$0$4787$4faf...@reader4.news.tin.it...
>
>> Andrea Francia wrote:
>>
>>> If I use the istruction
>>> stop n
>>> where n is a integer I found that the program terminate with n as
>>> exit code.
>>>
>>> I see that this happen compiling when I use the GNU Fortran compiler
>>> (gfortran).
>>>
>>> Is this behaviour standard, or it is a special behaviour of gfortran?
>>
>> Thanks everyone for the replies, now I know that this behaviour is not
>> part of the Fortran 95 standard, but it is part of the 1003.9-1992
>> standard and may be not avaialable on each Fortran 95 implementation.
>
>
> Sending the stop code to the OS as an exit status is not now part of
> the Fortran standard.
>
> However, Fortran 2008 will include an enhanced STOP statement. Two
> of the enhancements include displaying the stop code on ERROR_UNIT and
> using it as the process exit status, if the processor has such a
> concept. The details are in J3 paper 05-231r4.
>
Isn't it normally displayed on stdout? The most common I think I've
seen is either stdout or process exit code.

Craig Dedo

unread,
Feb 11, 2008, 10:06:51 PM2/11/08
to
"Gary Scott" <garyl...@sbcglobal.net> wrote in message
news:ex7sj.6731$5K1....@newssvr12.news.prodigy.net...

No. This is a common misconception. Where the stop code goes is
processor-dependent. Here is the relevant quote from section 8.4 of the Fortran
2003 standard.

[Begin quote from Fortran 2003]
Exection of a STOP statement causes normal termination (2.3.4) 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. If any exception (14) is signalling, the processor shall issue a
warning indicating which exceptions are signalling; this warning shall be on the
unit identified by the named constant ERROR_UNIT from the ISO_FORTRAN_ENV
intrinsic module (13.8.2.2).
[End of quote from Fortran 2003]

Gary Scott

unread,
Feb 12, 2008, 8:30:32 AM2/12/08
to
I realize that per the standard it is processor dependent. I meant that
in most actual current implementations, the stop code is either written
as text on stdout or is returned as an exit code to the shell/command
processor. Or maybe I'm just confused that stderr is the same as stdout
in this case.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

0 new messages