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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!mailrus!ames!hc!lll-winken!uunet!mcvax!enea!sommar From: sommar@enea.se (Erland Sommarskog) Newsgroups: comp.lang.ada Subject: Re: Overloading of ":=" Message-ID: <4189@enea.se> Date: 24 Dec 88 22:02:30 GMT Organization: ENEA DATA AB, Sweden List-Id: Mats Weber (madmats@elma.epfl.ch) writes: >I said: >> Generic >> Type Data_type is limited private; >> With procedure Assign(A : in out Data_type; B : in Data_type); >> With function ">"(A, B : Data_type) return boolean is <>; >> With function "<"(A, B : Data_type) return boolean is <>; >> Package Binary_trees is >> >>With an overloadable ":=" I could have declared the second parameter as >> >> With procedure ":="(A : in out Data_type; B : in Data_type) is <>; >> >Instanciating and using this generic package with Standard.Integer (or any >type that does not have a default initial value) is ERRONEOUS because the >formal parameter A of Assign or ":=" is of mode 'in out', hence the >corresponding actual paramter must be an initialized variable. This is of course erroneous no matter if we call the procedure Assign or ":=". The interesting point is of course if the erroneousity here is really crucial. As long as we don't actually read A, it doesn't really matter. So for standard.integer there is no problem. But for types with range constraints there could appear an unexpected and unnecessary constraint_error. However, we can easily circumvent this with a surpress pragma for our Assign procedure. Now, WHY, is A of mode "in out" in the Assign procedure? If we had "out" only, nothing "erroneous" could occur. And, any user who wanted to store a limited type in a tree would get no help from us. (The Text type from Text_handler in the LRM is a perfect victim.) -- Erland Sommarskog ENEA Data, Stockholm This signature is not to be quoted. sommar@enea.se