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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,75a8a3664688f227 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-09 12:44:03 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.mesh.ad.jp!newsfeed.rt.ru!news.algonet.se!algonet!newspeer.clara.net!newspeer2.clara.net!news.clara.net!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!grolier!club-internet!not-for-mail From: Laurent Guerby Newsgroups: comp.lang.ada Subject: Re: Parameter Modes, In In Out and Out Date: 09 Jan 2001 21:44:49 +0100 Organization: Club-Internet (France) Message-ID: <86itno316m.fsf@acm.org> References: NNTP-Posting-Host: nas12-219.vlt.club-internet.fr X-Trace: front3m.grolier.fr 979072942 12441 195.36.162.219 (9 Jan 2001 20:42:22 GMT) NNTP-Posting-Date: 9 Jan 2001 20:42:22 GMT X-Newsreader: Gnus v5.7/Emacs 20.5 Xref: supernews.google.com comp.lang.ada:3835 Date: 2001-01-09T20:42:22+00:00 List-Id: "i.a.mcleod" writes: > What is the difference between In Out and Out parameters according > to the way compilers handle these. I can't see any difference. An > out parameter is still taken in. I am confused by this anyone help? To add some code to the discussion, here is a case where changing "out" into "in out" changes the behaviour of a program from perfectly ok to erroneous: procedure T is Magic : constant := 12345; X : Integer := Magic; procedure P (Y : in out Integer) is begin null; end P; begin P (X); if X /= Magic then raise Program_Error; end if; end T; If you compile and run T, you'll get no output as expected. Now if you change the mode of Y to "out", if your compiler uses by copy passing for integer, you'll probably get a program_error, because the generated code for exiting P will set X with an unitialized stack value (the place reserved for the Y value). It is interesting to see that the P call "undo" the X initialization. So if you have a coding standard that says that all "variables" must be initialized, it's not enough in Ada, you also need to initialize all "out parameters of type not determined to be by-reference" to be safe from the unitialized variable syndrome in Ada. PS: this is not theory, I just saw (and fixed) an instance of this problem at work today (just with code a bit more convoluted ;-). -- Laurent Guerby