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



REH wrote:
Martin Krischik wrote:
Maciej Sobczak wrote:

Yes, classes are used to define new types. Is there any problem with
this? It is also necessary in Ada if we want to do just a bit more of
what is provided by type and subtype constructs.

Say:

type Y_Type is range 1 .. 10;
subtype X_Type is new x range 1 .. 5;

function F (X: X_Type) return Y_Type is
begin
return X + 3;
end F

Now I would expect that an Ada compiler will not insert any runtime checks
as X + 3 is allways in the range of Y_Type. However:

function G (X: X_Type) return Y_Type is
begin
return X + 7;
end G;

may well be outside the range of Y_Type and if so CONSTRAINT_ERROR will be
raised.

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 ().

I have done this.

I had a look. Looks impressive with all those includes. Looks like one
of thoses templates I never want to debug thrue.

But don't expect me to have found that magic static analysis something
trick. So:

How exactly did you do it?

Martin

.



Relevant Pages

  • Re: try to bluid gvd
    ... gcc: g-expect.adb: Ada compiler not installed on this system ... hmm it say i havn't a ADa compiler on my systeme... ... the standalone GVD is no longer updated since the debugging capability was rolled into GPS. ...
    (comp.lang.ada)
  • Re: Ada used in General Aviation (GA) applications?
    ... The US DoD has one major technology transfer success. ... The Ada paradox is that the Ada marketing ... As far as work on other languages, I agree that the Ada compiler ... However, there is one market where they should be competing, ...
    (comp.lang.ada)
  • Re: Ada memory management?
    ... > Pool in Ada to write own memory managers, ... with comprehensive memory reclamation is called 'full garbage collection'. ... I think, in reality, there is no native code Ada compiler which supports ... little or no dynamic memory allocation; the program does not give any (or ...
    (comp.lang.ada)
  • Re: microcontrollers supported for critical systems
    ... "not for use in life support systems as a critical component" ... Having an Ada compiler would be a big plus. ... the disclaimer "NOT FOR CRITICAL SYSTEMS USE" is ...
    (comp.arch.embedded)
  • Re: Dynamic array allocation and STL equivalents?
    ... > that there is a Gnu Ada compiler, so I installed it on a computer at ... I know people can be adverse to installing ... > arrays, and so on. ...
    (comp.lang.ada)