Hi Tanton,
My "Single User Specification, V.2" description isn't very detailed on this respect
(although it became pretty clear from the second sight). In the stddef.h document we
have following sentence:
"
ptrdiff_t
Signed integral type of the result of subtracting two pointers.
...
size_t
Unsigned integral type of the result of the sizeof operator.
"
So ptrdiff_t should be signed integer type wide enough to hold difference between
pointers (hence, sizeof(ptrdiff_t)==sizeof(void*)). size_t should be unsigned
integere wide enough as a pointers in this platform too (hence
sizeof(size_t)==sizeof(void*)). On some (most?) 64-bit platform we still have 32-bit
int values, while pointer is 64-bit wide. For example, on Alpha Tru64 we having:
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
typedef long ptrdiff_t;
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned long size_t;
#endif
Where sizeof(long)==8 while sizeof(int)==4. Taking into account the 64-bit nature of
the Alpha it should be faster to operate with long then with int (although I could
speculate on this respect).
Hence yes, INTVAL will be better to represent as size_t (if it should be unsigned) or
ptrdiff_t (if it should signed). Then it will have the 64-bit size on 64-bit
platforms and 32-bit on 32-bit platforms.
IMHO.
Happy coding,
Timur Safin
mailto:[EMAIL PROTECTED] http://timur.lanit.ru
mailto:[EMAIL PROTECTED]
----- Original Message -----
From: "Gibbs Tanton - tgibbs" <[EMAIL PROTECTED]>
To: "'Bryan C. Warnock '" <[EMAIL PROTECTED]>; "Gibbs Tanton - tgibbs"
<[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, October 04, 2001 6:48 PM
Subject: RE: replacing INTVAL in memory and register
: 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.
:
: Tanton
:
:
: -----Original Message-----
: From: Bryan C. Warnock
: To: Gibbs Tanton - tgibbs; '[EMAIL PROTECTED]'
: Sent: 10/4/2001 9:41 AM
: Subject: Re: replacing INTVAL in memory and register
:
: On Thursday 04 October 2001 10:38 am, Gibbs Tanton - tgibbs wrote:
: > INTVAL is used in memory and register to cast a pointer to an integer
: for
: > mathematical operators. Instead of using INTVAL I propose we use
: > ptrdiff_t or size_t (with my preference being the former). It would
: not
: > be used anywhere else, just when we need to do mathematics on
: pointers.
: > Both are given by the standard and both should be big enough to hold a
: > pointer (although I think only ptrdiff_t is guarenteed to be so...it
: is a
: > little fuzzy with size_t).
: >
: > Suggestions, comments, criticisms?
:
: Which standard?
:
: --
: Bryan C. Warnock
: [EMAIL PROTECTED]
: