std::ptrdiff_t
De 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. |
| Défini dans l'entête <cstddef>
|
||
| typedef /*implementation-defined*/ ptrdiff_t; |
||
std::ptrdiff_t est du type entier signé du résultat de la soustraction de deux pointeurs .
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.
[modifier] Notes
std::ptrdiff_t est utilisé pour l'arithmétique des pointeurs et l'indexation de tableau, si les valeurs négatives sont possibles. Les programmes qui utilisent d'autres types, tels que int, peut échouer sur, par exemple, Systèmes 64-bit lorsque l'indice dépasse INT_MAX ou si elle s'appuie sur 32-bit arithmétique modulaire .
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.
Lorsque vous travaillez avec le C + + contenant la bibliothèque, du type approprié pour la différence entre les itérateurs est le difference_type membre typedef, qui est souvent synonyme de std::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.
Seuls des pointeurs vers les éléments de la matrice de même (y compris le pointeur une delà de l'extrémité de la matrice) peut être déduite à partir de l'autre .
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.
Si un réseau est si importante (supérieure à PTRDIFF_MAX éléments, mais inférieure à SIZE_MAX octets), la différence entre les deux pointeurs ne soit pas représentable comme std::ptrdiff_t, le résultat de la soustraction de ces deux pointeurs est défini .
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.
Pour les tableaux ombles de moins de PTRDIFF_MAX, std::ptrdiff_t agit en tant que copie signée de std::size_t: il peut stocker la taille du tableau de n'importe quel type, et est, sur la plupart des plates-formes, synonyme de 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.
[modifier] Exemple
#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; }
[modifier] Voir aussi
| unsigned integer retournée par l'opérateur 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) | |
| décalage d'octet à partir du début d'un type standard à disposition élément spécifié 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. (fonction macro) | |