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: robert_dewar@my-dejanews.com Subject: Re: Pointer Arithmetic (was: Wanted: Ada STL....) Date: 1999/02/03 Message-ID: <799f5t$7je$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 440147169 References: <790f4q$3l@bgtnsc01.worldnet.att.net> <797na3$obg$1@nnrp1.dejanews.com> <798lej$69d$1@plug.news.pipex.net> X-Http-Proxy: 1.0 x13.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Wed Feb 03 12:24:35 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-02-03T00:00:00+00:00 List-Id: In article <798lej$69d$1@plug.news.pipex.net>, "Nick Roberts" wrote: > All unnecessary, Adam. Nowadays, (most) optimising > compilers do what you suggest automatically, without the > need for a pragma. Adam is claiming that the pointer arithmetic in C speeds up generated code by eliminating stride computations in some programs. While it is true that of course there are programs in which stride computations can be eliminated, the wide spread use of pointers in C in general *damages* the quality of the code by introducing uncontrolled aliasing that the compiler cannot deal with. If in C we see an isolated statement *p++ = 5; as opposed to x[i++] = 5; it is true we saved the stride computation in accessing the array, BUT, in the absence of global information quite unlikely to be available in the case Adam is looking at (i.e. the case where the index computation cannot be strength reduced), the assignment to *p++ potentially destroys all sorts of aliasing linkes, requiring things to be dumped from registers etc. This latter effect is FAR more damaging than the stride computation, which you might want to note is free on many machines in many cases (e.g. on the ia32 for strides of 1,2,4,8). The design of C in general is effective in allowing the user to do some optimization when using a completely stupid compiler that does no optimization at all. For example, the register declaration is in this category. But with a modern optimizing compiler, the excessively low level of C code (in particular its over-reliance on explicit pointers) is counter productive (it is interesting to note that most modern optimizing C compilers simply ignore the register declaration, they can do a better job than the programmer of figuring out what to keep in registers), but these same optimizing compilers cannot undo the (mis)use of pointer arithmetic for, e.g. array referencing. Robert Dewar -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own