Xref: utzoo comp.lang.c:6382 comp.sys.m68k:666 Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!bu-cs!polygen!pablo From: pablo@polygen.uucp (Pablo Halpern) Newsgroups: comp.lang.c,comp.sys.m68k Subject: Re: C machine Message-ID: <25@polygen.UUCP> Date: 20 Jan 88 02:23:10 GMT References: <461@auvax.UUCP> <9961@mimsy.UUCP> <166@teletron.UUCP> <6936@brl-smoke.ARPA> <147@ateng.UUCP> <39aca826.7f32@apollo.uucp> <7092@brl-smoke.ARPA> <708@umbc3.UMD.EDU> Reply-To: pablo@polygen.UUCP (Pablo Halpern) Organization: Polygen Corporation, Waltham, MA Lines: 54 In article <708@umbc3.UMD.EDU> alex@umbc3.UMD.EDU (Alex S. Crain) writes: >>>The result of subtracting two pointers is *defined* (K&R) to yield >>>a result of type int. >> >>That's another of the things that ANSI C intends to fix. > > >Fix? How pray tell would you fix it? make it machine dependent? or just >arbitrary? The ANSI Draft that I have (Oct 1, 1986) describes the header file which defines two types. As quoted from the document: The types are ptrdiff_t which is the signed integral type of the result of subtracting two pointers; and size_t which is the unsigned integral type of the result of the sizeof operator. (end quote) A machine with a short word but long pointer type (e.g. 68000, 8086) would have definitions like typedef long ptrdiff_t; typedef unsigned long size_t; in . Machines with short pointers (e.g. 8080, 6502) would have definitions like typedef int ptrdiff_t; typedef unsigned size_t; or better yet typedef long ptrdiff_t; typedef unsigned size_t; The reason for the long ptrdiff_t definition is that the difference between two unsigned, 16-bit pointers can excede the -32768 - +32767 range of a 16-bit two's compliment signed integer. Machines with long words and long pointers could use any of the above pairs of declarations. So the short answer to the question is: the difference of two pointers has a type that is machine (and compiler) dependent. But this is no worse (or better) than making the definition of an int machine dependent. Pablo Hapern, Polygen Corp. UUCP: {bu-cs,princeton}!polygen!pablo