Re: Teaching new tricks to an old dog (C++ -->Ada)

From: Dmitry A. Kazakov (mailbox_at_dmitry-kazakov.de)
Date: 03/23/05


Date: Wed, 23 Mar 2005 12:25:08 +0100

On Wed, 23 Mar 2005 12:36:46 +0200, Ioannis Vranos wrote:

> Pascal Obry wrote:
>
>> For a domain problem where you have to create an area centered on (0,0)
>> for example. What about a vector representing altitude, the sub-zero values
>> being under the water. Just some examples, I bet you'll be able to think about
>> lot more :)
>
> I think an associative container like map fits better to this. What do
> you do in Ada if you want to associate product names with prices, in the
> style
>
> productlist["something"]= 71.2;
>
> or a name with a number (string with string) in an address book
> application for example?
>
> namelist["Obry Pascal"]="321-45563";

In general, we use ADT. It is also a recommended practice in C++, BTW. What
would you do with

namelist["Pascal Obry"]="+0 321/45563 ";

or

namelist["321-45563"]="Pascal Obry";

Note that both Ada and C++ support ADT. Ada's arrays is just an example of
ADT. It is possible in C++ to implement an array as a set of classes though
it will be much more verbose and suffer from numerous drawbacks.

> Also may you tell me if that famous compile-time boundary checking
> applies (can be used) to user-defined containers too?

Of course it does. It is no different. The bounds can be specified either
as discriminants or as generic parameters (the latter has C++ equivalent).
As for the types with discriminants, they can be statically/dynamically
constrained and this is propagated down to the implementation where the
constraints are used. If corresponding methods are inlined then nothing
prevents the compiler from checking statically known bounds at
compile-time.

I seems to me that you still missing the point. Ada's ability to check
bounds is based on the idea of constrained subtypes. It is a fundamental
concept which C++ lacks. (The only weak form of constraining C++ supports
is templates specialization.)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Relevant Pages

  • Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... Note that both Ada and C++ support ADT. ... as discriminants or as generic parameters. ... constraints are used. ... prevents the compiler from checking statically known bounds at ...
    (comp.lang.ada)
  • Re: Constraints on values, promises to your compiler, pros cons
    ... static pre-/post-conditions and invariants and #2 dynamic constraints. ... pro: enables easy specializations ... I suppose it's not such a great example, because the compiler could do this automatically, but then we'd have to teach the compiler when to make a specialization and when not to. ... constrained index which range is from the argument array. ...
    (comp.lang.misc)
  • Re: Pure and internal procedures
    ... The idea of a pure procedure is: The compiler knows what effects a procedure has simply by knowing its interface. ... actually mandates that the processor *must check* that the programmer is ... It does that through a myriad of constraints. ... that there were requirements on pure procedures that were not ...
    (comp.lang.fortran)
  • Re: Why in stdint.h have both least and fast integer types?
    ... You mean that we might want to specify code constraints ... Why would just asking the compiler to ... I'm not sure that the C types provide that control - or they provide the ...
    (comp.lang.c)
  • Re: Pure and internal procedures
    ... the job of the compiler easier, because the net effect of all the ... actually mandates that the processor *must check* that the programmer is ... It does that through a myriad of constraints. ... that there were requirements on pure procedures that were not ...
    (comp.lang.fortran)