Path: utzoo!mnetor!uunet!mcvax!enea!tut!santra!clinet!msa From: msa@clinet.FI (Markku Savela) Newsgroups: comp.lang.c Subject: Indexing vs pointers Message-ID: <629@clinet.FI> Date: 27 Apr 88 16:48:30 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <2200@louie.udel.EDU> <587@vsi.UUCP> Reply-To: msa@clinet.UUCP (Markku Savela) Organization: City Lines Oy, Helsinki, Finland Lines: 31 Summary: It's not always clear which is better (performancewise...) In article <587@vsi.UUCP> friedl@vsi.UUCP (Stephen J. Friedl) writes: > >Let's put this goto business in perspective: > > /* > * strcpy() - written by John Doe > */ > strcpy(dst, src) > char dst[], src[]; > { > int i; > > for (i = 0; dst[i] = src[i]; i++) > ; > } > > Who objects to this? 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 code and a variation using pointers with LARGE MEMORY MODEL! 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...) The question is of course: is there really any penalty in using indexed versions with other architectures (like motorola)? -- markku savela, msa@clinet.fi