Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!labrea!decwrl!pyramid!uccba!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon Allbery) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <4485@ncoast.UUCP> Date: Tue, 8-Sep-87 18:13:25 EDT Article-I.D.: ncoast.4485 Posted: Tue Sep 8 18:13:25 1987 Date-Received: Thu, 10-Sep-87 07:06:45 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> <3812@spool.WISC.EDU> <2130@umn-cs.UUCP> <6357@brl-smoke.ARPA> <286@halley.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: comp.lang.c Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 30 Xref: mnetor comp.lang.c:4235 comp.unix.wizards:4159 As quoted from <286@halley.UUCP> by bc@halley.UUCP (Bill Crews): +--------------- | It seems to me that everyone is ignoring his Ed's point. Let's say a function | is to take two pointer arguments, a pointer to a string and a pointer | into the string. What you say seems to indicate that arithmetic expressions | involving both pointers, such as their difference, will produce unpredictable | results at execution time, because the called function has no way of knowing | whether the pointers are actually to the same "string" or not. +--------------- The point is that, while the subtraction might be doable, on a given architecture subtracting two pointers not into the same array might not have a meaning. On such hardware, the MMU knows what's what and the addresses reflect this. This is basically a declaration that the software isn't required to spin its wheels trying to deal with "unusual" hardware (can you truly call a PC "unusual? But large-model pointers are susceptible, since multiple : pairs may point to the same address. Pointer normalization is expensive). Note that in all of these cases, falling off the end of a string will still yield a valid pointer (for subtraction, at least) -- although some tagged architectures might hand you a segmentation violation when you try to go beyond the defined end of the string/data area. -- Brandon S. Allbery, moderator of comp.sources.misc {{harvard,mit-eddie}!necntc,well!hoptoad,sun!mandrill!hal}!ncoast!allbery ARPA: necntc!ncoast!allbery@harvard.harvard.edu Fido: 157/502 MCI: BALLBERY <> All opinions in this message are random characters produced when my cat jumped (-: up onto the keyboard of my PC. :-)