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. |
| Defined in header <cstddef>
|
||
| typedef /*implementation-defined*/ ptrdiff_t; |
||
std::ptrdiff_t es el tipo entero con signo del resultado de restar dos punteros .
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.
[editar] Notas
std::ptrdiff_t se utiliza para la aritmética de punteros y la indización de matriz, si los valores negativos son posibles. Los programas que utilizan otros tipos, como int, puede fallar en, por ejemplo, Sistemas de 64 bits cuando el índice sobrepasa INT_MAX o si se basa en 32-bit aritmética modular .
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.
Cuando se trabaja con el C + + biblioteca contenedor, del tipo adecuado para la diferencia entre iteradores es la difference_type miembro typedef, que es a menudo sinónimo 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.
Sólo punteros a los elementos de la misma matriz (incluyendo el puntero de uno pasado el final de la matriz) puede restarse de cada otro .
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 una matriz es tan grande (mayor de elementos PTRDIFF_MAX, pero menos de SIZE_MAX bytes), que la diferencia entre dos punteros no puede ser representable como std::ptrdiff_t, el resultado de restar dos punteros tales es indefinido .
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.
Para las matrices carbón inferiores a PTRDIFF_MAX, std::ptrdiff_t actúa como contraparte firmada de std::size_t: puede almacenar el tamaño de la matriz de cualquier tipo y es, en la mayoría de plataformas, sinónimo 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.
[editar] Ejemplo
#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; }
[editar] Ver también
| tipo entero sin signo devuelto por el operador 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) | |
| desplazamiento de bytes desde el comienzo de un tipo estándar de diseño de al miembro especificado 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. (función macro) | |