On Thursday 04 October 2001 10:48 am, Gibbs Tanton - tgibbs wrote:
> My ANSI and ISO Standard C reference manual (Plauger and Brodie) has it
> listed in <stddef.h> with the comment:
>
> ptrdiff_t( which is the type of the subtract operator when its operands
> are both pointers to data objects ).
>
> Althought the book was written in 1989 I still think it applies.
>
In C9x, pointer-integer conversions (except for 0) aren't guaranteed for
doing pointer arithmetic. (There was a good explanation that I ran across
the other day, but I can't seem to find it now.) I think the relevant
entries from the standard are:
3 An integer constant expression with the value 0, or such an expression
cast to type void
*, is called a null pointer constant.48) If a null pointer constant is
converted to a pointer
type, the resulting pointer, called a null pointer, is guaranteed to
compare unequal to a
pointer to any object or function.
4 Conversion of a null pointer to another pointer type yields a null
pointer of that type.
Any two null pointers shall compare equal.
5 An integer may be converted to any pointer type. Except as previously
specified, the
result is implementation-defined, might not be properly aligned, and
might not point to an
entity of the referenced type.49)
6 Any pointer type may be converted to an integer type. Except as
previously specified, the
result is implementation-defined. If the result cannot be represented
in the integer type,
the behavior is undefined. The result need not be in the range of
values of any integer
type.
--
Bryan C. Warnock
[EMAIL PROTECTED]