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: bobduff@world.std.com (Robert A Duff) Subject: Re: Is 'out' different from 'in out' (Was: Uninitialized "out" parameters) Date: 1996/07/22 Message-ID: #1/1 X-Deja-AN: 170061318 references: <31EEACDA.64880EEB@sage.inel.gov> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-22T00:00:00+00:00 List-Id: In article , Michel Gauthier wrote: >My intuitive view, and I guess the easier to teach, is that 'out' >parameters involve >initialization at the beginning of the subprogram. I agree that would be the intuitive view, and easier to teach. It's not true, though... On the other hand, it's close enough to being true that if you program that way, you won't get in trouble. >... I remember a discussion >during >the 9X process about 'out', and a conclusion that there was no longer a >difference >between 'out' and 'in out'. It depends on the type. For controlled types, there is no difference between 'out' and 'in out'. >... Of course, I do not assert that all 83 compilers did >behave the intuitive way. Well, it's not a *compiler* issue -- the RM says it. >So, I repost the question in another form : >___is there a difference between 'out' and 'in out' parameters ?___ It depends on the type. For scalars, yes. For tagged types, no. For untagged records with defaulted components, no. For unconstrained arrays, no. See the RM for the complete rule. Note that in Ada 83, your intuitive view was not true. One such case is when the formal is an unconstrained array. In that case, the bounds of the array are passed IN, even if the mode is OUT. For your intuitive view to work, Ada would have to have truly dynamic arrays (that is, arrays that can change size on assignment). Discriminants are similar to array bounds. >Consequent questions are : >___is an 'out' pointer reset to null when entering the subprogram ?___ No. It is set to whatever the actual was. >___is an 'out' controlled object finalised and reinitialised when entering >the subprogram ?___ No. (Even in your intuitive view, I don't understand why you say "when entering". If controlled types used by-copy semantics, then the formal would be assigned back to the actual after leaving the subprogram. At *that* point, the actual would be finalized, the copy done, the actual Adjusted, and finally the formal finalized. Initialize wouldn't be called.) >___is an 'out' record with initial values reinitialised when entering the >subprogram ?___ No. The rules just prevent it from becoming "deinitialized". >Finally, ___an AI discussion might be envisaged___. Don't you think so ? No. (Well, anybody's allowed to send in a comment, but my opinion is that the rules should not be changed, and my suspicion is that the ARG would agree. Of course, I don't speak for the ARG -- I just have one vote.) - Bob