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,FREEMAIL_FROM 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!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) From: Jim Rogers 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> <112rs0bdr2aftdf@corp.supernews.com> Followup-To: comp.lang.ada,comp.lang.c++ User-Agent: Xnews/5.04.25 Message-ID: Date: Wed, 09 Mar 2005 01:18:03 GMT NNTP-Posting-Host: 12.73.183.101 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1110331083 12.73.183.101 (Wed, 09 Mar 2005 01:18:03 GMT) NNTP-Posting-Date: Wed, 09 Mar 2005 01:18:03 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:8899 comp.lang.c++:44686 comp.realtime:1094 comp.software-eng:4650 Date: 2005-03-09T01:18:03+00:00 List-Id: CTips wrote in news:112rs0bdr2aftdf@corp.supernews.com: > Peter Amey wrote: >> >> >> Hans Malherbe wrote: >> >>>> support efficient, real-time safe environments >>> >>> >>> >>> Can you explain the "real-time" part? >>> >>> Reading this thread, it seems to me Ada's focus is on safety rather >>> than efficiency. >>> These safety constraints also tend to limit expressiveness. Not that >>> safety is bad, just that it's not free. >>> >> >> Actually, a close reading of the thread should have made it clear >> that the additional safety is indeed "free". > > Free? Well, lets look at one particular issue: pointers to arbitrary > locations. In C, its a common idiom to do the following: > foo(int * p) > { > int * z; > for( i ... ) { > ... p[i]...; > } > z = p; > } > > ... > foo( &x[lo] ); > ... > > Now, how can *any* language check to see that p[i] is within bounds? This is one of the unsafe idioms in C. The fact that you can declare a formal parameter as a pointer and then use that parameter as an array is unsafe. This can only be done safely if you either assume the existence of meta-data in the array to indicate the end of usable data (as in the \0 at the end of a string), or you must pass a second parameter telling you how long the array should be. Of course, that second parameter must be handled carefully. Improper values in the second parameter will cause you to skip array components or will create a bounds violation. Array bounds violations have for years been one of the most frequent C programming errors, and a boon to virus writers. Ada arrays are not so closely related to pointers. One can create an access type that "points" to an array. type int_array is array(1..10) of integer; type int_ptr is access int_array; Note that int_ptr is not a pointer to an integer, but a pointer to an array of integers. procedure foo(p : int_ptr) is begin for I in p.all'range loop ... p(I)... end loop; end foo; ip : int_ptr := new int_array; foo(ip); All this works without a problem in Ada. Jim Rogers