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: adam@irvine.com (Adam Beneschan) Subject: Re: Uninitialized "out" parameters Date: 1996/07/19 Message-ID: <4soje9$kjm@krusty.irvine.com>#1/1 X-Deja-AN: 169657492 references: <4smmhe$9cs@goanna.cs.rmit.edu.au> <4smo24$h25@krusty.irvine.com> <31EF9DFC.6FB4@csehp3.mdc.com> organization: /z/news/newsctl/organization newsgroups: comp.lang.ada Date: 1996-07-19T00:00:00+00:00 List-Id: "James A. Squire" writes: >Adam Beneschan wrote: >> >> 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'm not sure what you're referring to by "this" compiler behavior--whether you mean that it treats "op" as uninitialized, or whether you're referring to giving a warning about using an uninitialized parameter. The first is covered by 6.4.1(12-15): "For an out parameter that is passed by copy, the format parameter object is created, and: . . ." "For any other type [besides access types and certain composite types], the formal parameter is uninitialized. . . ." >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. I'd guess it's the same as for any uninitialized object, which is a bounded error that most likely won't be caught. -- Adam