Am 21.03.2025 um 11:50 schrieb Jose E. Marchesi:
Am 20.03.2025 um 21:50 schrieb James K. Lowden:
On Mar 13, 2025, at 8:04 AM, Simon Sobisch <simonsobi...@gnu.org> wrote:
exit() allows us to "pass to the operating system" directly; but it doesn't directly say
"success" or "fail".
Obviously the statements
STOP RUN WITH NORMAL STATUS 41
and
STOP RUN ERROR 41
Should have a different result for the operating system.
Or, obviously not.
For OSes I'm familiar with, there is no *definition* of
success/failure. There's just convention: 0 is success and nonzero
failure. Even that is honored in the breach, see diff(1).
IMO unless the OS defines success/failure outside the value of the
exit status value (above, 41), the COBOL compiler cannot supply
meaning to STOP RUN NORMAL or ERROR. It has no meaning in COBOL
because it has no meaning outside COBOL.
By that reasoning, the two statements above both return 41 because
there is no way to say more. It is for the caller to decide what to
do.
I do not think -41 is an option; the compiler should not make
arbitrary changes to the user's data.
It is temping to raise(SIG_TERM) for error, but again the 41 is
lost.
STOP RUN WITH ERROR "Don't do that, Jon!"
When no numeric value is supplied, IMO:
• STOP RUN WITH NORMAL STATUS becomes exit(EXIT_SUCCESS)
• STOP RUN WITH ERROR becomes exit(EXIT_FAILURE)
That satisfies the Principle of Least Astonishment. BTW those
values are defined by C, not POSIX.
--jkl
I agree that this could be a reasonable approach:
* STOP RUN WITH NORMAL STATUS becomes exit(EXIT_SUCCESS)
* STOP RUN WITH ERROR becomes exit(EXIT_FAILURE)
* Any text given goes to an internal DISPLAY (_possibly_ WITH ERROR
doing a DISPLAY UPON SYSERR)
If I'd not now that "some heavy business applications" actually pass
the error using specific values (one for deadlock, another for general
db issues, one for logic issues, ...) I'd say "screw the numbers -
just DISPLAY them".
So:
STOP RUN
EXIT PROGRAM
That's not identical, EXIT PROGRAM just leaves the current module (if
any, otherwise falls through),
should:
exit (EXIT_SUCCESS).
yes
Then:
STOP RUN WITH NORMAL STATUS <number>
should:
fprintf (stderr, "STOPPED WITH NORMAL STATUS %d", number);
exit (EXIT_SUCCESS);
no, applications already require the option to set that <number> as
return code to the OS.
Then:
STOP RUN WITH ERROR STATUS <number>
should:
fprintf (stderr, "STOPPED WITH ERROR STATUS %d", number);
exit (EXIT_FAILURE);
same here - error code needed to OS.
Note that:
STOP RUN WITH ERROR
would be
fprintf (stderr, "STOPPED WITH ERROR");
exit (EXIT_FAILURE);
and additional both have an optional literal (instead of the number)
STOP RUN WITH ERROR "Bad boy"
STOP RUN WITH alphanumeric-variable
*> possibly containing something like "order 999 was proceeded".
In this case we have exit (EXIT_SUCESS/EXIT_FAILURE) and
fprintf (stderr, "STOPPED WITH ERROR %s", message);
fprintf (stderr, "STOPPED NORMAL WITH MESSAGE %s", message);
or similar (and the stop message would likely be not all-caps and put
under gettext, of course)
Simon