Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mcnc!rti!xyzzy!meissner From: meissner@xyzzy.UUCP (Michael Meissner) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <226@xyzzy.UUCP> Date: Wed, 26-Aug-87 09:55:10 EDT Article-I.D.: xyzzy.226 Posted: Wed Aug 26 09:55:10 1987 Date-Received: Fri, 28-Aug-87 05:03:36 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> Reply-To: meissner@nightmare.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 21 Xref: mnetor comp.lang.c:3927 comp.unix.wizards:3899 In article <934@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes: # # 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. This is bad practice. I know of machines that have different formats for pointers to words and pointers to bytes, and other machines that use things like bit pointers. In none of these cases, or a segmented machine like the 80*86 will subtraction give you what you want. This is yet another symptom of the world is not a VAX syndrome. -- Michael Meissner, Data General. Uucp: ...!mcnc!rti!xyzzy!meissner Arpa/Csnet: meissner@dg-rtp.DG.COM