Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: pointer alignment when int != char * Message-ID: <6408@brl-smoke.ARPA> Date: Sat, 5-Sep-87 04:32:37 EDT Article-I.D.: brl-smok.6408 Posted: Sat Sep 5 04:32:37 1987 Date-Received: Wed, 9-Sep-87 02:09:34 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: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 33 In article <286@halley.UUCP> bc@halley.UUCP (Bill Crews) writes: >In article <6357@brl-smoke.ARPA> gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: >>In article <2130@umn-cs.UUCP>, randy@umn-cs.UUCP (Randy Orrison) writes: >>> In article <483@mtxinu.UUCP> ed@mtxinu.UUCP (Ed Gould) writes: >>> >Pointers may be subtracted *only* if they point to members of the same >>> >array of elements. >>> How is this determined? example: >>> strlen(s) >>> return (c-s); >>Obviously all characters in a string are in the same object (be it >>(char []) or chunk of malloc()-allocated storage. >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. I don't understand how you people are coming up with this misinterpretation. You postulate a pointer to the first element of a char[] array and a pointer to a later element of the same char[] array, then somehow that I don't understand conclude that there is some problem with the difference of those two pointers. But that difference is exactly one of the cases for which the proposed standard guarantees meaning. And in fact, such a strlen() implementation DOES work even on a segmented architecture. Are you perhaps thinking that the proposed standard insists that an implementation FAIL whenever the difference of two pointers not both in the same object is attempted? That WOULD be difficult to implement, all right, but that's not what the rules say. They just don't guarantee that the operation will succeed or have meaning, which is not at all the same thing.