From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,14aa27db81ce3b40 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed.freenet.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news-2.dfn.de!news.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: How to exit an Ada program with (unix shell) error code? Date: Mon, 4 May 2009 12:07:47 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <49ba30c9-a1e6-4346-8618-d256f87ac301@s31g2000vbp.googlegroups.com> <87ws8xkz0y.fsf@willow.rfc1149.net> <95866b61-f7e4-482d-8368-8b86528af578@b1g2000vbc.googlegroups.com> <10acae13-98dc-48da-9de4-9c01ea07abd4@g19g2000vbi.googlegroups.com> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: tigger.scc.uni-weimar.de 1241439229 21959 141.54.178.228 (4 May 2009 12:13:49 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Mon, 4 May 2009 12:13:49 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: <10acae13-98dc-48da-9de4-9c01ea07abd4@g19g2000vbi.googlegroups.com> Xref: g2news2.google.com comp.lang.ada:5679 Date: 2009-05-04T12:07:47+02:00 List-Id: On Mon, 4 May 2009, Ludovic Brenta wrote: > reinkor wrote on comp.lang.ada: > > Thanks, but how I terminate the program in a "natural" way > > (without using goto or "raise exception") ? > > Simply allow the execution to reach the "end;" of the main subprogram. > > with Ada.Command_Line; > procedure Exit_With_False is > begin > Ada.Command_Line.Set_Exit_Status (1); -- False, in shell terms Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); > end Exit_With_False; -- nothing else required I believe, it is preferable to use the predefined constants "Success" and "Failure" in Ada.Command line: 1. If you port your program to another (i.e. non-unix) system, it is not clear that "1" maintains the logical value "False". (Perhaps the RM is clear about that -- I didn't check ...) 2. Without the comment "-- False, in shell terms", many readers (except for unix-shell experts, of course) would rather expect Ada.Command_Line.Set_Exit_Status (1); to indicate a positive result ("True"), rather then "False". Here is a slightly larger example: with Ada.Command_Line; procedure False_If_No_Arguments is package ACL renames Ada.Command_Line; begin if ACL.Argument_Count > 0 then ACL.Set_Exit_Status (ACL.Success); else ACL.Set_Exit_Status (ACL.Failure); end if; end False_If_No_Arguments; P.S.: (As you see, you can indicate either a positive or a negative outcome without ever having to raise an exception ...) -- ------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------ Stefan dot Lucks at uni minus weimar dot de ------ I love the taste of Cryptanalysis in the morning! ------