Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Pointers vs. Arrays: an aside about efficiency Message-ID: <9224@watmath.UUCP> Date: Sun, 30-Sep-84 13:14:05 EDT Article-I.D.: watmath.9224 Posted: Sun Sep 30 13:14:05 1984 Date-Received: Mon, 1-Oct-84 03:36:23 EDT References: <15991@arizona.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 17 >for maximum efficiency, I have to write: > { struct foo *foop = fooarr; > for (i=0, i < FOOMAX; i++) > dostuff(*(foop++)); > } >instead of what I mean: > for (i=0; i < FOOMAX; i++) > dostuff(fooarr[i]); > > Roger Hayes Only on some machines does the former generate better code. Even on a Vax, for some storage class and type combinations, the amount of code would be the same (but the former might run *slower* cuz it is incrementing two variables each time around the loop). On some machines, pointer handling (other than just plain indirection) is so cumbersome that the second piece of code is always better. Kevin Martin, UofW Software Development Group