Re: where exactly c++,c fail and Ada gets thru'



Maciej Sobczak <no.spam@xxxxxxxxxxx> writes:
Martin Krischik wrote:
Now say we have a suitable C++ range template:
typedef range<int, 1, 10> Y_Type;
typedef range<Y_Type, 1, 5> 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 <typename Base_Type, Base_Type First, Base_Type Last>
range::operator = (Base_Type right)
template <typename Base_Type, Base_Type First, Base_Type Last>
range::operator + (Base_Type right)
template <typename Base_Type, Base_Type First, Base_Type Last>
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@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: Current status of Ada?
    ... learning and using this great language. ... The reason why compilers maker can't make their compiler totally free ... I agree with you that most of the links you can find on Ada websites ... AdaCore has contributed a free gnat compiler to ...
    (comp.lang.ada)
  • Re: Ravenscar-compliant bounded buffer
    ... the mid 1980's most compiler are FRONT_END compilers aka ... any system build around GNAT will contain the C code that GNAT ... The XGC Ada which is based on GNAT and uses C for its Real Time ... with VAXes for data processing applications. ...
    (comp.lang.ada)
  • Re: 7E7 Flight Controls Electronics
    ... Given that people had choices and Ada ... the 800 or so programming languages in use by the DoD, ... DoD1 was expected to provide a 'language of last resort', ... need modifications to a compiler to support particular requirements, ...
    (comp.lang.ada)
  • Re: Distributed Computing in Ada
    ... no shared memory. ... Ada tasks /can/ share memory, ... The problem is that the compiler can't know which variables are shared. ... The unit of distribution ...
    (comp.lang.ada)
  • Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... Though I haven't done so recently, back when I used Ada, nowhere close ... This can be ameliorated in a case like GNAT, where the Ada compiler ... _every_ programming language places severe limits on expressiveness; ... Ada's exception handling is also primitive at best (exceptionally so, ...
    (comp.lang.cpp)