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!news2.google.com!news.glorb.com!news2.glorb.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: How to exit an Ada program with (unix shell) error code? Reply-To: anon@anon.org (anon) References: <49ba30c9-a1e6-4346-8618-d256f87ac301@s31g2000vbp.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Fri, 15 May 2009 10:20:58 GMT NNTP-Posting-Host: 12.65.12.239 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1242382858 12.65.12.239 (Fri, 15 May 2009 10:20:58 GMT) NNTP-Posting-Date: Fri, 15 May 2009 10:20:58 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:5852 Date: 2009-05-15T10:20:58+00:00 List-Id: Well, Adam. You did not take account that when the OS calls a program, it has the following format, and is the only way any program or an Ada RTS will have access to the command line arguments and environment list. ( written in Ada type code, but normally written in C ) -- OS uses: Exit_Status := Application.all ( Argument_Count, Argument_List, Environment_List ) ; -- Calls an application ( any language: Ada, Cobol, Fortran, etc ). Now, if the language is Ada. The call is to the Ada RTS (normally created in the binding process) for the application , which in turn calls the user's "main subprogram". Then normally waits until user's "main subprogram" returns then the RTS returns a exit_status or return code to the OS. RM 10.2 (21) Since, the "implementation defined" requires a return code and uses this value as an exit_status. Ada must comply and return a exit_code. But an Ada programmer can create their own RTS. And this partition can be called directly by the OS. Just, compile and then link, and it will be ready to execute. In is Ada outline ( this type of Ada main subprogram can and is called directly by the OS ). This is the basic outline produced by "GNATBIND" with the results in b~.adb|s which are directly link to the OS. with System ; function Application ( Argument_Count : Integer ; Argument_List : System.Address ; Environment_List : System.Address ) return Integer is -- Should use "with Ada.Command_Line" instead of -- using "pragma Import" but that's GNAT design gnat_argc : Integer; gnat_argv : System.Address; gnat_envp : System.Address; gnat_exit_status : Integer; pragma Import (C, gnat_argc); pragma Import (C, gnat_argv); pragma Import (C, gnat_envp); pragma Import (C, gnat_exit_status); procedure Adainit is ... procedure Adafinal is ... begin -- set up Ada.Command_Line, if package is available gnat_argc := Argument_Count ; gnat_argv := Argument_List ; gnat_envp := Environment_List ; Adainit ; -- preform elaboration -- statement for the core of the user's program -- -- The binder in GNAT just calls the user subroutine -- by pragma Import. -- If the call is to a function, then it returns the -- exit status from that function. And some of -- Ada_Command_Line links are not available. Adafinal ; -- preform finalization return gnat_exit_status ; end Application ; This information is also demonstrated in Xavier Gave's toy lovelace series in 2004. Note: OS_Exit and OS_Abort requires the OS to shutdown the Ada RTS and other application's subtasks. And the finalization will not be preformed. Note: In the RM implementation is define as vendor or OS and OS environments. Martin. The RM 10.2 (29) is also, under the "Implementation Permissions" which means that the vendor does not have to obey the RM 10.2 (29) rule. Its just a strong suggestion. Binding process is referred to a process of creating an interface from Ada "main subprogram" to the "implementation execution environment" aka OS which normally done in two phases. The first, is using a Binder program to build the interface routine. And the second is to link and edit the routines and required packages together to build the partition. And In the simplest form a "Binding Process" is just another name for the linking process. In , Adam Beneschan writes: >On May 13, 7:55 pm, a...@anon.org (anon) wrote: > >> Now, all OS's (AT&T OS port, Linux, and Windows) shell or application >> loaders, calls a program using the following format: >> >> Exit_Status := Application.all ( Augment_Count, >> Argument_List, >> Environment_List ) ; > >I'll have to bow out of this argument, because you're making arguments >that I've already refuted multiple times, and you seem not to notice. >In particular, you still seem to assume that the OS is going to call >the Ada main subprogram directly, and I've dealt with this mistaken >assumption at least twice already. I don't feel like taking time >repeating myself any more. But I did want to point out a few places >where you're reading something in the RM that isn't there: > > >> This is defined from the "implementation's execution environment" which >> RM 1.1.3 (6) states that if it is "impossible or impractical" then Ada >> variations are permitted. Which states that all Ada partitions that are >> executed under this type of OS which calls a program as a function shall >> return a value aka Exit_Status. > >This is a huge stretch of interpretation. This paragraph is saying, >basically, that variations from the language are permitted if it's >impossible to implement things the way the standard says in a >particular execution environment; and you're interpreting this as a >*requirement* that the result of a function used as a main subprogram >must be an exit status. > > >> Then you have RM 10.2 (21) which states that Ada must conform to the >> "implementation's execution environment". By return an exit status >> unless it terminates abnormally since it was called as a function. >> >> 10.2 (21) A call to the main subprogram, if the partition has one. If >> the main subprogram has parameters, they are passed; where >> the actuals come from is implementation defined. What >> happens to the result of a main function is also >> implementation defined. > >How does this state that "Ada must conform to the implementation's >execution environment", as you say? This paragraph doesn't even >mention the execution environment. All it says is that "what happens >to the result of a main function is implementation defined", and the >phrase "implementation defined" means pretty much "whatever the >compiler writer chooses it to mean". If you believe "implementation >defined" means "determined in some way by the implementation's >execution environment", or "required to conform to it", well then--- >sorry, you are just not familiar with commonly used computer >terminology. > > >> 1.1.3 (12) Any result returned or exception propagated from a main >> subprogram (see 10.2) or an exported subprogram (see >> Annex B) to an external caller; > >The effect of this paragraph is to define the result of a main >subprogram as an "external interaction". That's all it does. The >section of the RM is giving a definition of the term "external >interaction". It makes no statement about what the result should be. > > -- Adam