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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,effb80d4bb7716dd X-Google-Attributes: gid103376,public From: William Clodius Subject: Re: Pointer Arithmetic (was: Wanted: Ada STL....) Date: 1999/02/03 Message-ID: <36B86CE2.2847@lanl.gov>#1/1 X-Deja-AN: 440212662 Content-Transfer-Encoding: 7bit References: <790f4q$3l@bgtnsc01.worldnet.att.net> <797na3$obg$1@nnrp1.dejanews.com> <36B78CDD.1372@lanl.gov> <798d2s$cce$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=us-ascii Organization: Los Alamos National Lab Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-02-03T00:00:00+00:00 List-Id: adam@irvine.com wrote: > > It's certainly conceivable (if you have a package that declares > an iterator, for example) that the index manipulation might not even be > handled within the same subprogram call. You might have to provide a > routine that steps to the next element of the array, then saves the index > in a global variable or an object's "work area" before the subprogram exits, > and then use the saved index the next time the subprogram is called. It > seems to me that it would be a lot harder for a compiler to perform the > analysis required to determine that the index should be implemented with > pointer arithmetic. Granted, when a program starts getting this complex, > it's hard for me to come up with a real-life example where the few nanoseconds > saved by avoiding multiplications would really make a difference. > The procedure call is liable to overwhelm any performance gains in any case, but it depends on how sophisticated the language is in its treatment of arrays. I am more familiar with Fortran than with Ada so I will use it as an example. In Fortran you can change the mapping of indices onto an array in different contests, i.e., treat a one dimensional array as a multidimensional array and a multidimensional array as one dimensional. Indexing in the one dimensional mapping is exactly equivalent to using a pointer on most processors. In Fortran for your example you could replace the global pointer value with a "global" index value into the single dimensional array mapping and there is no difference in what the compiler should be doing, in that context. In other contexts using arrays instead of pointers allows better out of bounds checking, and easier memory management by the processor. -- William B. Clodius Phone: (505)-665-9370 Los Alamos Nat. Lab., NIS-2 FAX: (505)-667-3815 PO Box 1663, MS-C323 Group office: (505)-667-5776 Los Alamos, NM 87545 Email: wclodius@lanl.gov