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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8893269a4640c798 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-17 13:55:28 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail From: "Mark A. Biggar" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3.1) Gecko/20030425 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: terminate applications References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <23ERa.75454$OZ2.12362@rwcrnsc54> NNTP-Posting-Host: 12.235.88.213 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc54 1058475326 12.235.88.213 (Thu, 17 Jul 2003 20:55:26 GMT) NNTP-Posting-Date: Thu, 17 Jul 2003 20:55:26 GMT Organization: Comcast Online Date: Thu, 17 Jul 2003 20:55:26 GMT Xref: archiver1.google.com comp.lang.ada:40437 Date: 2003-07-17T20:55:26+00:00 List-Id: Nick Roberts wrote: > "Riccardo" wrote in message > news:bf5uks$8n0$1@e3k.asi.ansaldo.it... > > >>is present a function that terminated applications? >>if yes what's? >> >>for example: exit(0); // language C > > > You should transfer control to the end of the main subprogram. For example: > > with Ada.Text_IO; > procedure Main is > Count: Natural := 0; > procedure Some_Inner_Procedure is > use Ada.Text_IO; > begin > Put_Line("Hello World"); > if Count = 100 then > -- we want to terminate program here > goto End_of_Program; > end if; > end Some_Inner_Procedure; > begin > loop > Some_Inner_Procedure; > Count := Count + 1; > end loop; -- infinite loop > <> -- this is how you write a goto label in Ada > end Main; > > This example doesn't necessarily show the most elegant technique, but it is > generally acceptable, and illustrates the idea. > > Of course, the best technique is always to let the program flow naturally to > the end of the main subprogram, if it is reasonable to do so. To illustrate > this, the above example would certainly be better rewritten like this: > > with Ada.Text_IO; > procedure Main is > procedure Some_Inner_Procedure is > use Ada.Text_IO; > begin > Put_Line("Hello World"); > end Some_Inner_Procedure; > begin > for i in 1..100 loop > Some_Inner_Procedure; > end loop; > end Main; > > I think it is quite important that, normally, you do not use any other > method to terminate an Ada program, since using another method could prevent > library packages (e.g. Ada.Text_IO, used in my examples) from finalizing > ('cleaning up') properly. If you really need to abort an Ada program form some deeply nested code, raising an exception is a reaaonable way to do it. All clean up actions are guarenteed to happen and you can add a handler to the main procedure to do any last gasp stuff cleanly. -- mark@biggar.org mark.a.biggar@comcast.net