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: Is 'out' different from 'in out' (Was: Uninitialized "out" parameters) Date: 1996/07/25 Message-ID: #1/1 X-Deja-AN: 170016176 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: henning.camb.inmet.com references: organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-07-25T00:00:00+00:00 List-Id: Michel Gauthier (gauthier@unilim.fr) wrote: : ... : Possible useful style rule : avoid 'out' parameters, since they : are error-prone, and prefer 'in out'. I don't agree. If the incoming value of a parameter is irrelevant to the algorithm of the routine, it should specify the parameter as an "out" parameter. This conveys more information to the user. Furthermore, if the parameter is of an elementary type, you can end up with more error possibilities with "in out", because if the caller forgets to initialize the actual parameter, you might or might not get a constraint error on the way in, depending on what "stack junk" is sitting in the variable when the call is made. With an "out" parameter, you only need to remember to initialize in one place, namely in the beginning of the routine with the OUT parameter. No constraint checks are performed on the way in for an elementary OUT parameter, eliminating the requirement for each caller to initialize the actual parameter to some irrelevant value. Note that if you believe it is rare to need to read an OUT parameter anyway, then there is no difference in "safety" between the Ada 83 and Ada 95 OUT parameters. If you believe it is common to need to read an OUT parameter, then in Ada 83, you had to introduce an extra variable, and then copy the value from that into the OUT parameter, creating *two* possibilities for error: forgetting to initialize this extra variable, and forgetting to copy the extra variable into the OUT parameter on all exit paths. The Ada 95 approach seems like a wash or a win in both cases. : Michel Gauthier / Laboratoire d'informatique : 123 avenue Albert Thomas / F-87060 Limoges : telephone +33 () 55457335 [or ~ 7232] : fax +33 () 55457315 [or ~7201] -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA