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: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Thread: 108717,a7c8692cac750b5e X-Google-Attributes: gid103376,gid115aec,gidf43e6,gid108717,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.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.realtime,comp.software-eng,comp.programming Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) From: Jim Rogers References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <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> <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> Followup-To: comp.lang.ada,comp.realtime User-Agent: Xnews/5.04.25 Message-ID: Date: Sun, 13 Mar 2005 03:17:33 GMT NNTP-Posting-Host: 12.73.183.38 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1110683853 12.73.183.38 (Sun, 13 Mar 2005 03:17:33 GMT) NNTP-Posting-Date: Sun, 13 Mar 2005 03:17:33 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:9283 comp.realtime:1402 comp.software-eng:4968 comp.programming:17891 Date: 2005-03-13T03:17:33+00:00 List-Id: CTips wrote in news:11369p5jrcc6835@corp.supernews.com: > > Oh, and just to illustrate another point about Ada, try running the Ada > program equivalent to the following program: > > #define N 30000 > #define N2 60000 > > 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]; > > } > } The function setup_array sets up the x array so that the first N elements each individually point to the elements of the p array, except for the last element in the p array. The second N elements of X point to the elements of the q array, except for the last element of the q array. > > void > do_array( > int * x[N2] > ) > { > int i; > int *p; > for( i = 0; i < N2; i++ ) { > p = x[i]; > p[1] = i; > } > } do_array has p point to the ith element in x, then treats p as an array and assigns its second element the value i. This sort of programming is generally foolishness. x[i] points to an int. Ints are not the same as arrays of ints. 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 kind of programming may be useful to virus developers, but I cannot see its usefulness to any other developers. > > int > main(void) > { > int p[N+1]; > int q[N+1]; > int * x[N2]; > int i; > > setup_array(x, p, q); > for( i = 0; i < 10000; i++ ) { > do_array(x); > } > return 0; > } > 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 Pa(2).all := 1; -- Assign 1 to the second value in the array Pa := X.Q; -- assign all elements of X.Q to Pa Pa(2).all := 1; -- Assign 1 to the second value in the array end Do_Array; P : Int_Array(1..N + 1); Q : Int_Array(1..N + 1); X : Combiner; begin -- set up the combiner to point to the elements -- in P and Q for I in 1..N loop X.P(I) := P(I)'access; X.Q(I) := Q(I)'access; end loop; for I in 1..10_000 loop Do_Array(X); end loop; end Array_Pointers; This program compiles and runs without errors. Jim Rogers