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,dab7d920e4340f12 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,dab7d920e4340f12 X-Google-Attributes: gid1014db,public From: clodius@hotspec.lanl.gov (William Clodius) Subject: Re: C is 'better' than Ada because... Date: 1996/08/05 Message-ID: #1/1 X-Deja-AN: 172579894 sender: clodius@hotspec.lanl.gov references: organization: Los Alamos National Laboratory newsgroups: comp.lang.ada,comp.lang.c Date: 1996-08-05T00:00:00+00:00 List-Id: In article <01bb80f9$5df267c0$9cee6fce@timhome2> "Tim Behrendsen" writes: Well, you say my anecdote says nothing, then turn around and say that it requires a "knowledgeable person" to do arrays correctly. If modern compilers are so good that programmers shouldn't have to worry about using arrays, then it should have been smart to optimize "misuse of arrays". It takes a knowledgeable person to do anything correctly including using pointers. The optimizations necessary to make properly used arrays equivalent in efficiency to properly used pointers are relatively simple. The optimizations necessary to optimize code that, say, assumes column major access in C arrays, are equivalent to the optimizations neceessary for code involving pointers emulating a multidimensional array, where the innermost loop is associated with large n strides, while an outer loop is associated with unit strides. The large strides can result in paging etc. and the code will typically be much more efficient if the inner and outer loops can be interchanged, but the compiler can only do that if it is certain that there are no side effects that are invalidated by such a reordering. This often requires complicated global analysis. The point is, pointers are native to machine architectures, so it's going to be easier for the optimizer to produce straightforward optimizations if the programmer doesn't do anything dumb by creating unsafe side effects. The point is that with pointers it is more difficult for the compiler to be certain that the programmer didn't do anything dumb by creating unsafe side effects. It is not enough for the programmer to not introduce side effects, the compiler has to verify that he didn't create side effects. Something that close to the machine can result in unstructured memory accesses, just as gotos can result in unstructured flow of control. However, unlike the gotos of most languages, the unstructured memory accesses associated with C are not easilly localized. Any pointer used as an argument to a function or as a global variable, from the computer's point of view, may be aliased with any other pointer used as an argument to the function or as a global variable. Unless it can verify that such aliasing has not occured by doing a complicated global analysis, many optimizations are disallowed by the language. Note: Fortran has a reputation for producing faster code than C in many situations, but untill recently it had only arrays and no pointers. -- William B. Clodius Phone: (505)-665-9370 Los Alamos National Laboratory Email: wclodius@lanl.gov Los Alamos, NM 87545