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



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. 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?

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
.



Relevant Pages

  • Re: Casting the return value of malloc() ?
    ... Why is it not good QoI? ... It is not the job of any programming language to avoid treading on the toes of another language. ... A C90 compiler that predefines __cplusplus is going to cause problems for such code, and the fact that it was legal for the implementation to do so won't make it's justifiably angry customers any happier about that fact. ... COBOL is not sufficiently similar to C to encourage the writing of code that is meaningfully compilable in both languages. ...
    (comp.lang.c)
  • Re: Type safety, C++ and code generation
    ... Martin Krischik wrote: ... R1 and R2 are equal to the compiler ... Maciej Sobczak: http://www.msobczak.com/ ... Programming: http://www.msobczak.com/prog/ ...
    (comp.lang.ada)
  • Re: Announce: gcc 4.4.2 for Mac OS X
    ... Martin Krischik ... negative) result on Snow Leopard? ... group is having trouble getting a Snow Leopard compiler running. ...
    (comp.lang.ada)
  • Re: ANN: compile gcc 3.4.1 How To
    ... Martin Krischik wrote: ... >> What compiler do you use to build ada support for gcc? ... build gnat on gcc 3.3 I can't compile all the tools. ...
    (comp.lang.ada)
  • Re: ADA Popularity Discussion Request
    ... Martin Krischik wrote: ... Mind you, if space is a problem, you can always ... does just as well, the allocations are performed by the compiler, ...
    (comp.lang.ada)