Xref: utzoo comp.sys.ibm.pc:22384 comp.sys.intel:611 Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!iuvax!bobmon From: bobmon@iuvax.cs.indiana.edu (RAMontante) Newsgroups: comp.sys.ibm.pc,comp.sys.intel Subject: Re: correct code for pointer subtraction Message-ID: <15891@iuvax.cs.indiana.edu> Date: 18 Dec 88 16:25:11 GMT Reply-To: bobmon@iuvax.UUCP (RAMontante) Organization: malkaryotic Lines: 20 chasm@killer.DALLAS.TX.US (Charles Marslett) writes: > > [...] And subtraction of >pointers OUGHT TO BE portable (to reiterate my original statement, the >Microsoft and Borland compilers are broken since they do not work "right"). I don't buy this; why do you say they don't work "right"? Pointer subtraction is only valid when the pointers are to the same array, and TurboC (at least) is simply referencing off the DS register in small memory models. So the pointers may be restricted in range, but they should give the correct number of ELEMENTS (not bytes, unless the array elements are byte-sized). Note that the original code in this thread made the mistaken assumption that its "diff()" function was dealing in pointers that were guaranteed to refer to the same array; in fact, they were independent pointers which happened, in the example call, to have received values based on a common array in the caller program. Perhaps this discussion ought to move to comp.lang.c.