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: stt@henning.camb.inmet.com (Tucker Taft) Subject: Re: Uninitialized "out" parameters Date: 1996/07/19 Message-ID: #1/1 X-Deja-AN: 169677320 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: henning.camb.inmet.com references: <4som64$775@newsbf02.news.aol.com> organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-07-19T00:00:00+00:00 List-Id: John Herro (johnherro@aol.com) wrote: : Samuel Tardieu writes that Ada 95 : allows reading of "out" parameters to allow things like: : > procedure Fact (N : in Positive; R : out Positive) is : > begin : > R := 1; : > for I in 2 .. N loop : > R := R * I; -- Note that the R out parameter gets read : here : > end loop; : > end Fact; : Yes, but this saves us only one variable declaration and one line in : the executable region over the way it would be done in Ada 83: : procedure Fact (N : in Positive; R : out Positive) is : S : Positive; -- new : begin : S := 1; : for I in 2 .. N loop : S := S * I; : end loop; : R := S; -- new : end Fact; It is hard to know which error is more common, the Ada 83 one where you create a local read/write variable and then forget to assign it on all exit paths to the OUT parameter, or the Ada 95 one where you forget to initialize the read/write OUT parameter. Having experienced the Ada 83 situation for 10 years, I remember having made the Ada 83 error several times. It is too early to tell how it will compare in frequency to the Ada 95 error. The main advantage is that it simplifies the language, since you only have one rule -- initialize your variables -- rather than two. Ada 83's unreadable OUT parameters require a special paradigm, and introduce a second class of errors, when you need to build up an answer incrementally. : - John Herro : Software Innovations Technology : http://members.aol.com/AdaTutor : ftp://members.aol.com/AdaTutor -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA