🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3325

sizeof(size_t) == sizeof(ptrdiff_t) required?

#3325
From: D. Scott Bigham
Date: Fri, 29 Jan 1993 03:47
32 lines
1684 bytes
A friend of mine maintains a freeware C compiler -- non-conforming,
unfortunately.  In a recent discussion, he commented that one of the
ways in which his compiler is non-conforming is that sizeof(size_t)
does not equal sizeof(ptrdiff_t) (in particular, sizeof(size_t)=2 and
sizeof(ptrdiff_t)=4).

Now, I haven't a copy of the Standard, but I can find no wording in K&R2
to this effect.  I can argue convincingly that sizeof(ptrdiff_t) must be
at least as large as sizeof(size_t); the declaration:

char a[N];

is legal for any N in the range of a size_t, and the value &a[N]-&a[0]
must be representable for all such N.  I cannot, however, come up with
a plausible reason why sizeof(ptrdiff_t) could not be greater than
sizeof(size_t).  Given:

char *a, *b;

if the value (b-a) is not in the representable range of a size_t, then
by definition a and b do not point into the same object; the compiler is
not obliged to do anything sensible in this case, but it may certainly
choose to do so.

Opinions?  Does the Standard specify this?

						-sbigham
-- 
Scott Bigham                   | The opinions expressed above are
dsb@romeo.cs.duke.edu          | (c) 1993 Hacker Ltd. and cannot be
bigham@hercules.acpub.duke.edu | copied or distributed without a
    (but not for long)         | Darn Good Reason(tm).
Technical Details
Message-ID: <728279270@majors4.cs.duke.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!gatech!concert!duke!dsb

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!gatech!concert!duke!dsb
From: dsb@duke.cs.duke.edu (D. Scott Bigham)
Newsgroups: comp.std.c
Subject: sizeof(size_t) == sizeof(ptrdiff_t) required?
Message-ID: <728279270@majors4.cs.duke.edu>
Date: 29 Jan 93 03:47:51 GMT
Organization: n. Arrangement in an orderly or logical fashion.  See "miracle".
Lines: 32