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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,803df5f3f60558d5 X-Google-Attributes: gid103376,public From: "James A. Squire" Subject: Re: Uninitialized "out" parameters Date: 1996/07/19 Message-ID: <31EF9DFC.6FB4@csehp3.mdc.com>#1/1 X-Deja-AN: 168867009 sender: Ada programming language references: <4smh9i$gp5@krusty.irvine.com> <4smmhe$9cs@goanna.cs.rmit.edu.au> comments: Gated by NETNEWS@AUVM.AMERICAN.EDU content-type: text/plain; charset=us-ascii organization: MDA Avionics Tools & Processes mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.01 (X11; I; HP-UX A.09.01 9000/715) Date: 1996-07-19T00:00:00+00:00 List-Id: Adam Beneschan wrote: > > Dale Stanbrough writes: > > >Adam Beneschan writes: > >"Well, you can't read an "out" parameter at all, so it's illegal to use > > "op" in the right-hand side of your assignment. So the compiler > > should give you an error. Also, in Ada83, you'll get an error because > > I needs to be declared before the code for SubP appears. > > > > If you change op to an "in out" parameter, you'll be reading an > > uninitialized variable, but typically neither the compiler nor the > > runtime will complain." > > > > > >Ada95 does allow you to read out parameters. The code written simply > >uses an uninitialized variable, and I would imagine it would be declared > >erroneous by the LRM. > > Sorry, I wasn't aware of this change. > > This rule change frightens me a little. In the posted example: > > procedure SubP (op : out integer) is > begin > op := op + 1; > end SubP; > > I've been known to accidentally type "out" when I mean "in out". In > Ada 83, the compiler would catch me, but now it won't, and the effect > will be very different because here the "op" on the right side of the > assignment is always uninitialized. However, I guess a smart compiler > would let me know that I'm using an uninitialized parameter, and > perhaps the advantages of letting you read an OUT parameter after > you've written to it outweigh this disadvantage. I tried to find out from the LRM if this compiler behavior is required, but I don't see it anywher in chapter 6. I do know that in 6.1.1 of the Ada95 Rationale, it has the following paragraph: "For Ada 95, we have removed the restrictions on the use of out parameters. Specifying that a formal parameter is of mode out indicates that the caller need not initialize it prior to the call. However, within the procedure, once the ^^^^^^^^ parameter has been initialized, it may be read and updated like any other ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable. As with a normal variable, it is an error to depend on the value of an out parameter prior to its being initialized." but I don't know if that's a compiler error or a run-time error. From the context, I'd guess a run-time error. -- James Squire mailto:ja_squire@csehp3.mdc.com MDA Avionics Tools & Processes McDonnell Douglas Aerospace http://www.mdc.com/ Opinions expressed here are my own and NOT my company's "Nice shark...pretty shark..." -- Londo, "The Gathering"