Xref: utzoo comp.sys.ibm.pc:37295 alt.msdos.programmer:605 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!rutgers!cmcl2!yale!cs.yale.edu!spolsky-joel@CS.YALE.EDU From: spolsky-joel@CS.YALE.EDU (Joel Spolsky) Newsgroups: comp.sys.ibm.pc,alt.msdos.programmer Subject: Re: Turbo C far pointers Message-ID: <4037@cs.yale.edu> Date: 31 Oct 89 05:35:06 GMT References: Sender: news@cs.yale.edu Reply-To: spolsky-joel@CS.YALE.EDU (Joel Spolsky) Followup-To: comp.sys.ibm.pc Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 23 In article hp0p+@andrew.cmu.edu (Hokkun Pang) writes: >> 2) You really should use "ptr[i]" rather than "*(ptr+i)". It effectively >> does the same thing, but it makes for much cleaner and much more >> readable code. > >I read from a book that "ptr[i]" will be converted to "*(ptr+i)" by the >compiler, so the "*(ptr+1)" is faster than "ptr[1]". Is that right? That's ridiculous. *(A+1), A[1], and 1[A] all produce exactly the same code. There is no reason to believe that the compiler prefers one over the other, or that the compiler implements A[1] by first expanding that to *(A+1). For all you know it does the opposite. And even if it did make a difference, it would be so small as to be imperceivable even on the worlds slowest C compiler running on an HP-41C. +----------------+----------------------------------------------------------+ | Joel Spolsky | bitnet: spolsky@yalecs.bitnet uucp: ...!yale!spolsky | | | internet: spolsky@cs.yale.edu voicenet: 203-436-1538 | +----------------+----------------------------------------------------------+ #include