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-Thread: 103376,8ca14c11fd6d2e56 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: generic parameter Copy for primitifs types. References: <1119544911.159343.288010@g43g2000cwa.googlegroups.com> In-Reply-To: <1119544911.159343.288010@g43g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 24 Jun 2005 03:10:46 GMT NNTP-Posting-Host: 4.240.114.55 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1119582646 4.240.114.55 (Thu, 23 Jun 2005 20:10:46 PDT) NNTP-Posting-Date: Thu, 23 Jun 2005 20:10:46 PDT Xref: g2news1.google.com comp.lang.ada:11608 Date: 2005-06-24T03:10:46+00:00 List-Id: nblanpain@hotmail.com wrote: > > ----- > generic > type T_Item is private; > with procedure Copy (Left : in out T_Item; Right : in T_Item); > package Toto is > ... > end Toto; Not that both ":=" and Copy are available to Toto for type T_Item. That seems odd; Toto is probably incorrectly specified. Making Left (in Copy) mode in out can cause a problem with elementary types. Such types are checked for subtype conformance on copy-in to subprograms, and again on copy-out (elementary types are passed by copy). Consider a type type T is range 1 .. 10; and a variable V : T; and a procedure Copy such as yours for T. If I write Copy (Left => V, Right => T'First); the value of V will be checked against the range of T on copy-in to the procedure. Objects of type T will probably take 8 bits (or more) on most processors; thus, it's likely that the initial value of V will not be in T, and the call to Copy will raise Constraint_Error. While you cannot pass default assignment to the generic, you can create a helper generic to make this case easier: generic -- Assignment type Item is private; procedure Assignment (To : out Item; From : in Item); procedure Assignment (To : out Item; From : in Item) is -- null; begin -- Assignment To := From; end Assignment; Then you can write procedure Assign is new Assignment (Item => Integer); package Dunno is new Toto (T_Item => Integer, Copy => Assign); If you change Copy to Assign and use a default parameter: with procedure Assign (To : out T_Item; From : in T_Item) is <>; then the 2nd instantiation can become package Dummo is new Toto (T_Item => Integer); -- Jeff Carter "Sheriff murdered, crops burned, stores looted, people stampeded, and cattle raped." Blazing Saddles 35