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,7833d36bbd0d6fcd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Offical Ada FAQ Date: Fri, 26 Nov 2004 10:01:10 +0100 Message-ID: <1pc1yfy2p7wqf.bhwh9bkg6kl9.dlg@40tude.net> References: <2004112423222516807%david@bottoncom> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de VAR1zRTt4J5cEPqIxGMF3gOhqfCvlnskX7BOd+nFKYBt4PS40= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:6495 Date: 2004-11-26T10:01:10+01:00 List-Id: On Fri, 26 Nov 2004 09:13:41 +1100, Brian May wrote: >>>>>> "David" == David Botton writes: > > David> Strong typing can be carried too far, and some amount of > David> implicit conversion is essential to make OOP palatable. But > David> note that in Ada 95, even with OOP, we don't allow implicit > David> conversions that truncate the extension part of a record > David> (this is a relatively common mistake in C++ when passing > David> parameters by value). > > I would be curious to know more about this common mistake in C++... Perhaps David meant: class A { public : int Field1; }; void Foo (A X); class B : public A { public : int Field2; }; void Foo (A X) { printf ("%i", ((B*) &X)->Field2); // Surprise, surprise } int main () { B Baz; Baz.Field2 = 123; Foo (Baz); // Prints garbage or crashes return 0; } But the above is NOT a mistake. It is absolutely correct behavior! The actual error is an attempt to cast to B something what is not B. Should Ada allow by-value parameter passing for some of tagged types (why not), the effect would be exactly the same: truncating extra members. The only difference to C++ would be that [view] conversion to B or B'Class would raise Constraint_Error, while C++ cast swallows anything told. > Does this work with both "in", "in out" and "out" parameters? > > For out parameters, what happens if the derived type has extra fields > not in the parent? Is this legal? If it is legal are the extra fields > defined? It is just view conversions. The tag of a tagged "out" parameter is set before the call, so it is legal and safe (up to Constraint_Error). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de