ptrdiff_t

来自cppreference.com
< c‎ | types

在头文件 <stddef.h> 中定义
typedef /*implementation-defined*/ ptrdiff_t;
ptrdiff_t两个指针相减的结果是有符号整数类型.
原文:
ptrdiff_t is the signed integer type of the result of subtracting two pointers.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 注释

ptrdiff_t用于指针的算术运算和数组下标,如果负值是可能的。使用其他类型,如int的程序,可能会失败,例如:当该指数超过64位系统INT_MAX,或者如果它依赖于32位模数.
原文:
ptrdiff_t is used for pointer arithmetic and array indexing, if negative values are possible. Programs that use other types, such as int, may fail on, e.g. 64-bit systems when the index exceeds INT_MAX or if it relies on 32-bit modular arithmetic.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
只有相同的数组元素(包括过去数组结尾的指针1)的指针,也可以彼此相减.
原文:
Only pointers to elements of the same array (including the pointer one past the end of the array) may be subtracted from each other.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
如果数组是如此之大(大于PTRDIFF_MAX元素,但小于SIZE_MAX字节),两个指针之间的差可能并不表示为ptrdiff_t减去两个这样的指针,结果是未定义.
原文:
If an array is so large (greater than PTRDIFF_MAX elements, but less than SIZE_MAX bytes), that the difference between two pointers may not be representable as ptrdiff_t, the result of subtracting two such pointers is undefined.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
对于字符数组短比PTRDIFF_MAXptrdiff_t的签名对应的size_t作为:它可以存储任何类型的数组的大小,并是在大多数平台上,代名词intptr_t).
原文:
For char arrays shorter than PTRDIFF_MAX, ptrdiff_t acts as the signed counterpart of size_t: it can store the size of the array of any type and is, on most platforms, synonymous with intptr_t).
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 另请参阅

返回无符号整数类型的sizeof运营商
原文:
unsigned integer type returned by the sizeof operator
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

(typedef) [edit]
byte offset from the beginning of a struct type to specified member
(函数宏) [edit]
C++ documentation for ptrdiff_t