Xref: utzoo comp.sys.ibm.pc:22152 comp.sys.intel:595 Path: utzoo!attcan!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.sys.ibm.pc,comp.sys.intel Subject: Re: correct code for pointer subtraction Summary: But the code's still wrong! Message-ID: <470@sdrc.UUCP> Date: 12 Dec 88 22:22:08 GMT References: <597@mks.UUCP> <8377@bloom-beacon.MIT.EDU> <8455@sequent.UUCP> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 24 In article <8455@sequent.UUCP>, sch@sequent.UUCP (Steve Hemminger) writes: > I believe the ANSI std and K&R say pointer subtraction is only allowed inside > one data structure/array. Since the small/medium/large model only allows > arrays <64K, only a 16bit result needs to be computed. Any code that > depends on subtracting pointers into two totally seperate arrays is > non-portable. But even then you need a **17** bit (intermediate) result since intermediate results between -65534 and +65534 are possible (assuming the worst case - an array of 2-byte objects). Since dpANS treats the element just past the end of the array as valid for pointer arithmetic, 17 bits really only allows objects to be 64k - 1 bytes long. Huge model is the only one that supports 64k objects completely. All the others only support 32767. Compiler vendors who tell you otherwise are lying (although not necessarily intentionally). ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.uucp 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "Save the Quayles" - Mark Russell