Re: How to exit an Ada program with (unix shell) error code?



On May 5, 8:34 am, Jean-Pierre Rosen <ro...@xxxxxxxxx> wrote:
Adam Beneschan a écrit :> Right; and even if your Ada compiler *does* support functions that
return integers as main programs, and you're compiling for some
operating system with an "x" in its name (or Solaris), this does *not*
mean that the Ada compiler will treat the function result as the
status code. The compiler could decide that the function result is
something to be formatted and spit out onto standard output. If an
Ada implementation supports parameters and/or function results on main
programs, the language leaves it up to the implementation how those
are interpreted. There's no rule that says that the interpretation
has to mimic the behavior of the C language (thank God). So anon's
solution may work on GNAT, but it can't be assumed to work anywhere
else.

That's right from a legalistic point of view, but don't forget that
compiler writers are not masochists.

That last statement might be tautologically false. :) :) :)

In any case, if you're implying that writing the extra code needed to
get the program to display the function result on the standard output
is an act of self-inflicted pain---trust me, it's nowhere near as
painful as trying to understand and implement 3.10.2.


If an implementation supports
functions returning integers as main programs, I would be very surprised
if it was not interpreted as the return code, since this is what the
consumer would expect...

Irvine Compiler's Ada compiler (the one I masochistically work on
maintaining) does behave in the way I described. Main subprograms can
be procedures or functions; they can take parameters that are scalars
or String (which are parsed from the command line); and they can be
functions that return scalars or String, with the result being
formatted and displayed on the standard output. The compiler was
originally written to run on Unix and VMS---and, by the way, I'm not
sure that VMS supports the convention that a main program's function
result becomes the return status (which is not a simple zero or non-
zero as it is on Unix, if I recall correctly). The compiler also runs
on a variety of other targets, although the parameters and function
result aren't supported in most cases.

Surprised? Well, the compiler is consistent across platforms and with
respect to allowing various types to be used as function results. It
wouldn't make any sense to break consistency and make integer-
returning functions on Unix-type platforms behave differently. And
nobody has ever complained about it. As for whether it's what I'd
expect if I were a consumer... I'm not much of a C hack, but when I
do use C I use exit() to set the status code, not "return", which
seems to me to pervert the meaning of what a "function" and a function
result should be; or as Georg said it, it's "playing tricks" with the
language. I don't feel any particular need to expect Ada compilers to
support the same sort of trickery C programmers are used to.

But that's just my opinion.

-- Adam



.



Relevant Pages

  • Re: RFC : SOME IDEAS FOR THE APPLE II FPGAers
    ... After porting a compiler to a new machine, ... use the other half of the machine's memory for profile counters ... middling peaks for fast call expansion, and the rest for interpretation. ... etc. and hand craft the critical sections in assembly language. ...
    (comp.sys.apple2)
  • ADA compilers can reject types arbitrarily?
    ... I assume I can expect an O'size spec to be ... a compile time error if the operational spec grows independant of the ... in favor of compiler dependant but readable code. ... So an ADA compiler can arbitrarily decide whether to accept a ...
    (comp.lang.ada)
  • Re: How to exit an Ada program with (unix shell) error code?
    ... compilers must support is "public ... mean that the Ada compiler will treat the function result as the ... There's no rule that says that the interpretation ...
    (comp.lang.ada)
  • Re: No call for Ada (was Re: Announcing new scripting/prototyping language)
    ... If you insist on only compiling it as C, at least use a good compiler. ... something about the language itself, ... A properly functioning Ada compiler will catch _this_ stupid mistake ... catch all such stupid mistakes is taking a leap well beyond reality. ...
    (comp.lang.ada)
  • Re: No call for Ada (was Re: Announcing new scripting/prototyping language)
    ... If you insist on only compiling it as C, at least use a good compiler. ... something about the language itself, ... A properly functioning Ada compiler will catch _this_ stupid mistake ... catch all such stupid mistakes is taking a leap well beyond reality. ...
    (comp.lang.cpp)