Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!columbia!rutgers!husc6!necntc!ames!ptsfa!ihnp4!inuxc!iuvax!bsu-cs!dhesi From: dhesi@bsu-cs.UUCP (Rahul Dhesi) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <934@bsu-cs.UUCP> Date: Fri, 7-Aug-87 09:42:05 EDT Article-I.D.: bsu-cs.934 Posted: Fri Aug 7 09:42:05 1987 Date-Received: Sun, 9-Aug-87 02:51:40 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> Reply-To: dhesi@bsu-cs.UUCP (Rahul Dhesi) Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 28 Xref: mnetor comp.lang.c:3526 comp.unix.wizards:3604 In article <179@xyzzy.UUCP> meissner@nightmare.UUCP (Michael Meissner) writes: >All of the standards say that >pointer subtraction is only defined within an aggregate. This allows putting >each top level item into a separate segment on say an 80*86, and only doing >the subtraction between the two offsets. Many MSDOS compilers do this >already. To subtract two independent large-model pointers of the type segment:offset, I tried this: (unsigned long) p2 - (unsigned long) p1 I was hoping that the cast to unsigned long would convert each pointer to a sort of absolute memory address in bytes, and the subtraction would yield the difference in bytes. Under Borland's Turbo C at least, such a cast is a no-op, so the resulting unsigned long does not necessarily increase monotonically with increasing memory address to which the original pointer points. I understand that the requirement on such casts is that they be unsurprising and reversible, to the extent that these are possible. It would be nice if "unsurprising" were interpreted to mean that the subtraction I was attempting would work. The only catch is that reversibility would be weakened because in the 8086 architecture many different long pointers can point to the same address, but I could live with that. -- Rahul Dhesi UUCP: {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi