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: 108717,a7c8692cac750b5e X-Google-Thread: 103376,703c4f68db81387d X-Google-Attributes: gid108717,gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!l41g2000cwc.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.programming,comp.lang.ada Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) Date: 12 Mar 2005 22:59:11 -0800 Organization: http://groups.google.com Message-ID: <1110697151.726709.276550@l41g2000cwc.googlegroups.com> References: <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <1110396477.596174.285520@o13g2000cwo.googlegroups.com> <112vb2t8eonuhed@corp.supernews.com> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <113394jjvppao64@corp.supernews.com> <1133s3qnmqmbjfb@corp.supernews.com> <4232a9f7$0$26552$9b4e6d93@newsread4.arcor-online.net> <11369p5jrcc6835@corp.supernews.com> NNTP-Posting-Host: 69.170.70.49 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1110697156 324 127.0.0.1 (13 Mar 2005 06:59:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 13 Mar 2005 06:59:16 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: l41g2000cwc.googlegroups.com; posting-host=69.170.70.49; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.programming:17899 comp.lang.ada:9291 Date: 2005-03-12T22:59:11-08:00 List-Id: Arthur J. O'Dwyer wrote: > On Sun, 13 Mar 2005, Jim Rogers wrote: > > This sort of programming is generally foolishness. > > x[i] points to an int. Ints are not the same as > > arrays of ints. > > Not in Ada, no. I believe that was the point CTips was demonstrating > with this code snippet: The same code, written in Ada, would be much > longer, slower, and immensely more cumbersome for the reader. I don't > know to what purpose one might put the demonstrated code, so I think it's > kind of a silly example. The proper retort is, "Ah, but Ada wasn't > designed for such nonsensical tasks! Show me a /useful/ algorithm > where C is more expressive!" On the other hand I have read arguments in comp.lang.c where some C-bashing person tries to claim that pointers and arrays in C are indistinguishable. The C faithful clearly stated that there is a difference. I was trying (however poorly) to restate that position. A pointer to an int is used to pass either an int by reference, or the pointer to an array of int. The parameter passed is not an array, but the address of the start of the array. Unfortunately, the way many people write C it is not possible from inside a called function to determine whether the address passed was really to an array of int, or to a single int. The function is left to make assumptions about this issue. > > > Treating the address of any int > > as the beginning of an array is a formula for buffer > > overflow, as is demonstrated in this example. > > This example does not appear to contain any buffer oveflow. > If you think it does, please point it out to me. I may have > missed something. > Ok, I understand why he made p and q with N+1 elements. This allows him to point past the Nth element without leaving either p or q's allocated space. Nonetheless, the data element in the highest position of those arrays has not been initialized. This is not the best practice. > > > I suspect you want a solution written as you would write > > it in C. That is not quite reasonable. Each language has > > its own best approach to a given problem. I chose to write > > the Ada solution as a solution to what I understand is the > > problem you are trying to solve. > > > > procedure Array_Pointers is > > N : constant Positive := 30000; > > > > type Int_Array is array(Positive range <>) of aliased Integer; > > type Int_Ptr is access all Integer; > > type Element_Ptr is array(Positive range 1..N) of Int_Ptr; > > type Combiner is record > > P : Element_Ptr; > > Q : Element_Ptr; > > end record; > > > > procedure Do_Array(X : Combiner) is > > PA : Element_Ptr; > > begin > > Pa := X.P; -- assign all elements of X.P to Pa > > Um... surely there's a better way to do this! Are you really > copying N references here, or is something going on more subtle > than the comment indicates? That is exactly what I am doing, which matches nicely with the actions taken in the C code for the function setup_array: void setup_array( int * x[N2], int p[N+1], int q[N+1] ) { int i; for(i=0; i< N;i++){ x[i]-&p[i]; x[i_N]=&q[i]; } } This appears to also be copying two sets of N pointers. > > > Pa(2).all := 1; -- Assign 1 to the second value in the array > > For my own edification: Am I correct in thinking that the ".all" > is superfluous in this expression? > Not at all. This is equivalent to the C syntax *(p[1]) = 1; Jim Rogers