Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!wjvax!miker From: miker@wjvax.UUCP (Michael Ryan) Newsgroups: comp.lang.c Subject: Re: Indexing vs pointers Message-ID: <1272@wjvax.UUCP> Date: 5 May 88 20:30:03 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <629@clinet.FI> Organization: Watkins-Johnson Co., San Jose Lines: 54 Summary: whoa In article <629@clinet.FI>, msa@clinet.FI (Markku Savela) writes: > In article <587@vsi.UUCP> friedl@vsi.UUCP (Stephen J. Friedl) writes: > >Let's put this goto business in perspective: [ ... ] > > for (i = 0; dst[i] = src[i]; i++) > > ; [ .. ] > I don't! I'm actually using similar loops in my C-programs > that are written for MS-DOS machines. Just try compiling the above [ ..] > Compare the results (in ASM). Believe or not, the variant > using indexes is much more compact than the one using pointers (and > saying "register i" improves it even more...) ok , far char type/size objects this works swell. but chars are not an interesting pointer case! if , for instance, you have a struct of , say , 60 bytes or so, like this: struct foo { char name [ 32 ]; long value; int asst[ 5 ]; }/**/ struct foo dave[ 200 ]; accessing dave with indexes becomes harrowing if your compiler is not smart I currently use , much to my chagrin, Msoft 5.0. an index like dave[3] becomes mov ax, 02EH ; or there about.. imul 3 ; .... excuse the mistakes, this is just an ex. to do anything interesting , meaning multiple struct access, becomes an exercise in integer multiplication. no, the Msoft 5.0 optimizer does nothing to change multiple array index accesses into pointer accesses. why ? I do not know. a million excuses to any compiler that does index/pointer optimization. our VAX cc doesn't while our Integrated Solutions cc does. can anyone name an MS-DOS product that does ? if one does not know the intelligence of one's compiler I recommend avoiding indexes, unless one has a great deal of time and don't we all. -- ==== *michael j ryan *{..!pyramid,..!decwrl!qubix}!wjvax!miker *Watkins-Johnson Co., San Jose CA : (408) 435 1400 x3079 * above views are not necessarily those of Watkins-Johnson Co.