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: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: mfb@mbunix.mitre.org (Michael F Brenner) Subject: Re: OO, C++, and something much better! Date: 1997/01/14 Message-ID: <5bg8nk$ckf@top.mitre.org>#1/1 X-Deja-AN: 209808214 references: <32DA822A.2FD8@lmtas.lmco.com> organization: The MITRE Corporation, Bedford Mass. newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-14T00:00:00+00:00 List-Id: > Why does unchecked_conversion require copying? The following > code works fine with my copy of GNAT, and I've used the same > technique on Ada 83 compilers as well... First, the code in that post gets the following error message under gnat: spectre% gnatmake test_uc gcc -c test_uc.adb test_uc.adb:13:12: left hand side of assignment must be a variable gnatmake: "test_uc.adb" compilation error Second, unless the code generator in the compiler includes specific copy optimizations to eliminate the copy, unchecked_conversion is in the form of a function which logically returns a copy of the argument. Unless the compiler has this optimization the code will make a copy. This is in contrast to the situation where you use address clauses to overlay variables. Then the two variables are permanent aliases to each other, and you do not have to copy the value from one to the other. There are many algorithms in mathematics that require an object of one type to be considered as an object of another type, for example, fast Fourier transforms, set membership, ASCII to numerical conversion, braid group conjugacy, floating point normalization, integer square root, extracting bits from binary numbers, binary radix exchange sorting, hash codes, multiple precision integer division, parity bits, garbage collectores, cyclical redundancy checks, segmenting, and pixel maps. In each of these cases, an ordinary exact number (which happens to be a twos complement on every CPU that survived the IBM PC era), needs to be viewed as an algebraic integer with Addition, Subtraction, Multiplication, and Division, YET at the same time, as a bit string to do And, Or, Xor, Substr, Set_bit, Set_substr, First_nonzero_bit, Impl, Nand, Nor, Next_bit, and Bit_merge sequentially according to a bit_pattern_vector. In all of these algorithms there is one choice of representing the two different memory addresses with an unchecked_conversion to get the data from one address to the other. And there is another choice to represent it as two objects of different types at the same memory address with an address clause. Without a copy optimization to remove the copy implied by the output of the function unchecked_conversion (or any other function), the algorithms which use unchecked_conversion will run slower than those using the address overlay technique. In some cases, such as FFTs and hash codes, that copy time can occur several times and add up to more than the rest of the algorithm, so there is evidence for requiring support for address overlays, and for asking vendors to improve the code generation of their compilers to automatically alias the addresses of objects being converted through unchecked conversion to their targets address, when this can be done, so that no copy has to take place. Purists sometimes forbid explicit aliasing via addressing overlays. But that can be short-sighted for the above algorithms, because aliasing in the address dimension also occurs whenever a variable has more than one name: equivalences, renames, overlays, common variables, objects with tags or discriminants, polymorphisms, external objects shared with other languages, parameters passed by reference, and pointers. The last three are more troublesome than the rest (for analysis tools) because they potentially involve multiple copies of pointers. Aliasing also occurs in the name dimension when a name can refer to two different objects, e.g., array elements, homonyms, and inheritance.