From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!t-online.de!tsicnews.teliasonera.com!news.otenet.gr!news.grnet.gr!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Thu, 24 Mar 2005 13:55:07 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1111665309.881405@athnrd02> References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> <423fe9df$0$11476$9b4e6d93@newsread2.arcor-online.net> <1111521825.653841@athnrd02> <424094b0$0$11481$9b4e6d93@newsread2.arcor-online.net> <1111568404.687226@athnrd02> <3afmc2F6b3mooU1@individual.net> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1111665309 8069 193.92.150.73 (24 Mar 2005 11:55:09 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Thu, 24 Mar 2005 11:55:09 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: <3afmc2F6b3mooU1@individual.net> Cache-Post-Path: newsfd02!unknown@ppp16-adsl-51.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:9900 comp.lang.c++:47052 comp.realtime:1680 comp.software-eng:5285 Date: 2005-03-24T13:55:07+02:00 List-Id: Peter Amey wrote: > Of all the comments in this rambling (but remarkably bloodless) thread, > this is the one that, for me, gets closest to the fundamental > philosophical difference between the C language family and Ada. > > The [0, +] styles does indeed map closely to what is happening in the > machine; however, for me, what is happening in the machine is generally > much less interesting than what is being represented in my problem > domain. I am always struck by the way a C user's first thought always > seems to be about how many bits he needs to represent something where an > Ada user is concerned with real-world values and leaves the bit size to > be chosen by the compiler. Of course, when writing an interface to a > hardware device, we have to worry about bit patterns but I certainly > want to stop doing that as soon as possible and worry about the problem > domain instead. > > So, for an array, I want to index it with a problem domain entity and > let the compiler turn that into a wholy uninteresting set of address > offsets. > > Ionnis wanted an example of negative indexes. How about: > > type X_Values is range -5 .. 5; > type Y_Values is range 0 .. 25; > type Graph is array (X_Values) of Y_Values; > Squares : constant Graph := (25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25); I have to say that for simple cases of things like that - in case we want to associate the x ranges with the y values - in C++ we "keep in mind" that [0] is for -5, etc, in the style: unsigned is used for Y_Values. // Indices stand for [-5, 5] X values vector Graph(11); Graph[0]= 25; For much more ranges one can use a map. If a map is considered expensive, a way I can think is using a vector of pairs: // first for X_Values, second for Y_Values vector > Graph(11); Graph[[0].first= -5; Graph[0].second= 25; // Range checked Graph.at(1).first= -4; Graph.at(1).second= 16; It isn't that incomprehensible if you are used to programming in C++. -- Ioannis Vranos http://www23.brinkster.com/noicys