std::ptrdiff_t
提供:cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <cstddef>
|
||
| typedef /*implementation-defined*/ ptrdiff_t; |
||
std::ptrdiff_t二つのポインタを減算した結果の符号付き整数型です.
Original:
std::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] ノート
負の値が可能であればstd::ptrdiff_tは、ポインタ演算と配列のインデックス付けのために使用されます。そのようなintなどの他のタイプを使用するプログラムは、、で失敗する可能性があり、例えば、 64ビットシステムでは、32ビットモジュラー演算に依存している場合、インデックスがINT_MAX超えたり.
Original:
std::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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
C + +のコンテナライブラリを操作する場合、反復子の差のために適切な型は、しばしばdifference_typeと同義であるメンバのtypedefstd::ptrdiff_t、です.
Original:
When working with the C++ container library, the proper type for the difference between iterators is the member typedef difference_type, which is often synonymous with std::ptrdiff_t.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
同じ配列(配列の終わり過去ポインタ1を含む)の要素へのポインタのみが互いに減算することができる.
Original:
Only pointers to elements of the same array (including the pointer one past the end of the array) may be subtracted from each other.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
アレイは、2つのポインタ間の差はPTRDIFF_MAXとして表現できない可能性があること、(SIZE_MAX要素よりも大きいが、std::ptrdiff_tバイト未満)ほど大きい場合には、そのような2つのポインタの減算結果は未定義です.
Original:
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 std::ptrdiff_t, the result of subtracting two such pointers is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
PTRDIFF_MAXの署名された相手とstd::ptrdiff_t、std::size_t行為より短いchar型の配列の場合:それは任意の型の配列のサイズを格納していることができ、ほとんどのプラットフォームで、std::intptr_tと同義).
Original:
For char arrays shorter than PTRDIFF_MAX, std::ptrdiff_t acts as the signed counterpart of std::size_t: it can store the size of the array of any type and is, on most platforms, synonymous with std::intptr_t).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] 例
#include <cstddef> int main() { const std::size_t N = 100; int* a = new int[N]; int* end = a + N; for(std::ptrdiff_t i = N; i>0; --i) *(end - i) = i; delete[] a; }
[編集] も参照してください
| sizeof子によって戻された符号なし整数型 Original: unsigned integer type returned by the sizeof operator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (typedefです) | |
| バイトは、標準レイアウトの種類の先頭から指定されたメンバへのオフセット Original: byte offset from the beginning of a standard-layout type to specified member The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数マクロ) | |