Path: utzoo!mnetor!uunet!husc6!bbn!rochester!udel!burdvax!sdcrdcf!ism780c!news From: news@ism780c.UUCP (News system) Newsgroups: comp.lang.c Subject: Re: C machine Message-ID: <8728@ism780c.UUCP> Date: 27 Jan 88 20:58:06 GMT References: <461@auvax.UUCP> <28700025@ccvaxa> <7159@brl-smoke.ARPA> Reply-To: marv@ism780.UUCP (Marvin Rubenstein) Organization: Interactive Systems Corp., Santa Monica CA Lines: 29 In article <7159@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <28700025@ccvaxa> aglew@ccvaxa.UUCP writes: >>I suppose that there is no equivalent to %p for pointers for >>ptrdiff_t? > >Why should there be? printf( "%ld", (long)( - p1) ); The problem with a header file defining a type ptrdiff_t is that the the defined type must be one of the types in the base C language. If an implementation defines ptrdiff_t such that sizeof(ptrdiff_t) == sizeof(void*) then p1-p2 may overflow. BTW, the definition of pointer difference in K&R is "if p and q point to members of the same array , p-q is the number of elements between p and q." One way to interpret this is the following: el1 el2 el3 ^ ^ | | p q As can be seen from the diagram the number of elements "between" p and q is 1 (not 2). Furthermore, the number of elements between p and q is clearly the same as the number of elements between q and p. i.e, p-q == q-p and no overflow is possible. I hope the defininition in the proposed standard is less ambigious than the wording in K&R. Marv Rubinstein -- Interactive Systems