Path: utzoo!mnetor!uunet!lll-winken!lll-tis!mordor!sri-spam!sri-unix!garth!walter From: walter@garth.UUCP (Walter Bays) Newsgroups: comp.lang.c Subject: Re: Indexing vs pointers Message-ID: <624@garth.UUCP> Date: 2 May 88 19:12:41 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <2200@louie.udel.EDU> <587@vsi.UUCP> <629@clinet.FI> Reply-To: walter@garth.UUCP (Walter Bays) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 32 In article <629@clinet.FI> msa@clinet.UUCP (Markku Savela) writes: >In article <587@vsi.UUCP> friedl@vsi.UUCP (Stephen J. Friedl) writes: >> strcpy(dst, src) >> char dst[], src[]; >> { >> int i; >> >> for (i = 0; dst[i] = src[i]; i++) >> ; >> } > 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)? I think that with a good compiler, for any architecture, you're better off writing in a simple and straightforward manner. The Clipper compiler will compile the example above using pointers just as if you had written it with pointers. The difference is, if the pointers are programmer declared, they have to be kept around, while if they are compiler generated, the registers are available for reuse. And of course if you use the library version (written with specific knowledge of the architecture) it will be faster still. -- ------------------------------------------------------------------------------ Any similarities between my opinions and those of the person who signs my paychecks is purely coincidental. E-Mail route: ...!pyramid!garth!walter USPS: Intergraph APD, 2400 Geng Road, Palo Alto, California 94303 Phone: (415) 852-2384 ------------------------------------------------------------------------------