std::ptrdiff_t
Da cppreference.com.
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <cstddef> | ||
typedef/*implementation-defined*/ ptrdiff_t; | ||
std::ptrdiff_t è il tipo intero con segno del risultato della sottrazione dei due puntatori.
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.
[modifica]Note
std::ptrdiff_t è utilizzato per l'aritmetica dei puntatori e l'indicizzazione di array, se i valori negativi sono possibili. Programmi che utilizzano altri tipi, come int, può fallire su, ad esempio Sistemi a 64 bit, quando l'indice supera INT_MAX o se si basa su 32 bit aritmetica modulare.
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.
Quando si lavora con il C + + contenitore di libreria, il tipo corretto per la differenza tra gli iteratori è il difference_type membro typedef, che spesso è sinonimo di 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.
Solo i puntatori alle elementi della matrice stessa (compreso il puntatore uno oltre la fine della matrice) possono essere sottratti tra loro.
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.
Se un array è così grande (maggiore di elementi PTRDIFF_MAX, ma meno di SIZE_MAX byte), che la differenza tra due puntatori non possono essere rappresentabile come std::ptrdiff_t, il risultato della sottrazione tali due puntatori è indefinito.
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.
Per gli array char di lunghezza inferiore a PTRDIFF_MAX, std::ptrdiff_t funge da controparte firmata std::size_t: è in grado di memorizzare le dimensioni della matrice di qualsiasi tipo ed è, sulla maggior parte delle piattaforme, sinonimo di 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.
[modifica]Esempio
#include <cstddef>int main(){conststd::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; }
[modifica]Vedi anche
senza segno tipo intero restituito dal gestore 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) | |
byte offset dall'inizio di un layout di tipo standard per membro specificato 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. (funzione macro) |