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



Maciej Sobczak wrote:

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?

The point is - of corse - it that the semantic tree of the Ada
compiler contains the information that X will be in the range of (1 ..
5) and then the optimizer can easily calculate that (1 .. 5) + 3 < 10
and then optimize away the check.

The sematinc tree of the C++ will contain the information that X is in
the range of (-2*32 .. +2*32-1) and that is a pretty useless
information to the optimizer.

Martin

.



Relevant Pages

  • Re: Standard Ada Preprocessor (Was: why ada is so unpopular ?)
    ... something in only one "Ada approved" way. ... I have seen many projects killed by version skew. ... And that is why bringing other standards into the language and compiler ... Every standard that becomes explicitly part of the language ...
    (comp.lang.ada)
  • Re: How to check a Float for NaN
    ... don't know that the compiler will actually do anything. ... Anyway, Wikipedia describes the IEC 559/IEEE 754 standard, but as ... Ada doesn't fully support this standard ...
    (comp.lang.ada)
  • 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: In-Out Parameters for functions
    ... That is an issue I think we Ada fans often get caught up in. ... *theory* an Ada compiler could do blah blah blah...." ... the standard allows it, but nobody does it. ... standard allows it if they can't get a compiler that does it? ...
    (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)