Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ut-sally!im4u!esc-bb!halley!bc From: bc@halley.UUCP (Bill Crews) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <286@halley.UUCP> Date: Tue, 1-Sep-87 19:09:38 EDT Article-I.D.: halley.286 Posted: Tue Sep 1 19:09:38 1987 Date-Received: Sat, 5-Sep-87 17:20:49 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> <3812@spool.WISC.EDU> <2130@umn-cs.UUCP> <6357@brl-smoke.ARPA> Reply-To: bc@halley.UUCP (Bill Crews) Organization: Tandem Computers, Austin, TX Lines: 24 Xref: mnetor comp.lang.c:4154 comp.unix.wizards:4077 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. -bc -- Bill Crews Tandem Computers Austin, Texas ..!seismo!ut-sally!im4u!esc-bb!halley!bc (512) 244-8350