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: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: OO, C++, and something much better! Date: 1997/01/13 Message-ID: #1/1 X-Deja-AN: 209553391 references: organization: New York University newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-13T00:00:00+00:00 List-Id: Don Harrison said "Yes, these mechanisms are inherently unsafe but their purpose is to allow different views of the same data. There are different ways of acheiving that and some ways are safer than others. For example, UNCHECKED_CONVERSION is safer than overlaying because the data is copied thus protecting the original object." That is a misconception. Unchecked_Conversion does not require the data to be copied. The whole point of 13.9(12) is to remove this requirement: 12 An implementation may return the result of an unchecked conversion by reference, if the Source type is not a by-copy type. In this case, the result of the unchecked conversion represents simply a different (read-only) view of the operand of the conversion. The design principle here is that since this is a d0-it-at-your-own-risk and make-sure-you-know-what-you-are-doing operation, it is inappropriate to waste time trying to increase the safety of the operation. If you want to ensure that a copy is made, you must make the copy. Note that in the common case of: a := unchecked_convert (b); the assignment makes a copy anyway (and this is the case where avoiding the requirement for unchecked_conversion to make a copy of its own improves efficiency -- well to be fair the compiler can optimize this case since it is transparent, but encouraging return by reference will generally improve efficiency, and is unlikely to be noticeable. GNAT does take advantage of this permission where appropriate, and UC for large objects works by pointer punning if the alignments are compatible (if the alignments don't match, or more specifically if the target has a stricter alignment than the source, then of course you have no choice but to make a copy.