C machine

Doug Gwyn gwyn at brl-smoke.ARPA
Sat Jan 30 06:01:57 AEST 1988

In article <8728 at ism780c.UUCP> marv at ism780.UUCP (Marvin Rubenstein) writes:
-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.

"As with any other arithmetic overflow, if the result does not fit in the
space provided, the behavior is undefined."

It is up to the implementation to choose a reasonable size for ptrdiff_t.

-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:

Yes, that's been fixed in the proposed ANSI C standard.

More information about the Comp.lang.c mailing list