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,25b9eb5c3a89bced X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!news-east.rr.com!news-feed-01.rdc-kc.rr.com!news.rr.com!cyclone2.kc.rr.com!news2.kc.rr.com!tornado.socal.rr.com.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: where exactly c++,c fail and Ada gets thru' References: <1145852356.559455.222600@i39g2000cwa.googlegroups.com> <1145855124.720029.35280@t31g2000cwb.googlegroups.com> <1235818.stAph9vF03@linux1.krischik.com> From: Keith Thompson Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:p1e8lYiTSgsRz7Qfo3uVDlRvyPo= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 27 Apr 2006 21:19:23 GMT NNTP-Posting-Host: 66.75.136.120 X-Complaints-To: abuse@rr.com X-Trace: tornado.socal.rr.com 1146172763 66.75.136.120 (Thu, 27 Apr 2006 14:19:23 PDT) NNTP-Posting-Date: Thu, 27 Apr 2006 14:19:23 PDT Organization: Road Runner High Speed Online http://www.rr.com Xref: g2news2.google.com comp.lang.ada:3971 Date: 2006-04-27T21:19:23+00:00 List-Id: Maciej Sobczak writes: > Martin Krischik wrote: >> Now say we have a suitable C++ range template: >> typedef range Y_Type; >> typedef range X_Type; >> Y_Type F (X_Type X) >> { >> return X + 3; >> } >> Y_Type G (X_Type X) >> { >> return X + 7; >> } >> Now anyone up to the challenge to define: >> template >> range::operator = (Base_Type right) >> template >> range::operator + (Base_Type right) >> template >> range::range (Base_Type right) >> in such a way that it works like Ada - inclusive the *realistic* >> change that >> the compiler will optimize away the range check in F (). > > The C++ standard does not define to what extent the compilers are > allowed to optimize the resulting code. Actually, I think it does; it just doesn't define to what extent compilers are *required* to optimize. (In C, allowed optimizations are determined by what's loosely called the "as-if rule"; C++ is probably similar.) > This is the quality of > implementation issue and an area of competition between compiler > vendors. Without any further checks I can claim that it is possible > for the compiler to optimize it the way you want. > > And without any further checks I take the risk to claim that the Ada > standard does not require any conforming compiler to optimize range > checks away as you described (or please throw some references) - > similarly, this is the QoI issue. > > So - what was your point? Probably the point was that range checks are an intrinsic feature of Ada, and any decent Ada compiler will optimize them as much as practical. In C++, on the other hand, any range checks would have to be done as explicit user code, and a typical C++ compiler might be less likely to recognize an idiom that it can optimize. A sufficiently clever C++ compiler should be able, in most cases, to optimize as well as a sufficiently clever Ada compiler (though I suspect Ada's aliasing rules allow for better optimizations in some cases). I have no idea whether current C++ compilers are "sufficiently clever". -- Keith Thompson (The_Other_Keith) kst-u@mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this.