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: 103376,cef1e23795181e0c X-Google-Attributes: gid103376,public From: robert_dewar@my-dejanews.com Subject: Re: Alternate to Unchecked_Conversion - Portable? Date: 1999/02/25 Message-ID: <7b3fk2$lnk$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 448274584 References: <36d05e39.0@news.pacifier.com> <36d2638e.6427631@nntp.concentric.net> <7avplr$jl5$1@nnrp1.dejanews.com> <7b2j34$drp$3@plug.news.pipex.net> X-Http-Proxy: 1.0 x2.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Feb 25 12:27:52 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-02-25T00:00:00+00:00 List-Id: In article <7b2j34$drp$3@plug.news.pipex.net>, "Nick Roberts" wrote: > |> procedure Op (O : T) is > |> > |> OO : constant TT := UC (O); > |> begin > If the type T were not a 'small' type (which can fit into > one or two registers) -- and I think that's what the > context of this thread suggests -- > I would be surprised by an optimising compiler which did > make a copy. Whyever should it make a copy? Well Nick, you seem to be operating as a user looking at a specific case and wondering why it is not optimized, rather than an implementor writing an optimizing compiler. All I can say is come back when your optimizing compiler is complete, and see if you handle this case, and if so why and how it is a special case of a more general optimization principle. Obviously there are two quite separate objects here, and indeed a programmer would expect that O'Address and OO'Address would be different, so in the general case I am not even sure the optimization is valid at all. This is in fact a very delicate optimization, the question of when you could treat initialized constants as implicit renamings is indeed an interesting one. Note of course that if you write OO : TT renames UC (O); then an Ada 95 (but not necessarily an Ada 83) compiler may routinely create a reference rather than a copy in this situation. That's because of the important change in Unchecked_Conversion semantics in Ada 95 that allows return by reference. I often find that users who do not understand compilers and optimizing compilers in particular well are often in a mode of looking at specific examples and saying "why is this paticular case not generating this particular code?" Humans are VERY good at special casing, but of course the challenge in an optimizing compiler is to find general safe optimization principles. Compilers that have lots of special case optimization are exactly the ones that have lead many programmers to distrust optimization :-) -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own