offsetof
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>
|
||
| #define offsetof(type, member) /*implementation-defined*/ |
||
El offsetof macro se expande a una constante de std::size_t tipo, el valor de los cuales es el desplazamiento, en bytes, desde el principio de un objeto del tipo especificado para su miembro especificado, incluido el relleno, si cualquier .
Original:
The macro offsetof expands to a constant of type std::size_t, the value of which is the offset, in bytes, from the beginning of an object of specified type to its specified member, including padding if any.
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.
Contenido |
[editar] Notas
Si
type no es un tipo de normas de diseño, el comportamiento no está definido .Original:
If
type is not a standard-layout type, the behavior 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.
Si
member es un miembro estático o un miembro de la función, el comportamiento es indefinido .Original:
If
member is a static member or a function member, the behavior 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.
El desplazamiento del primer elemento de un tipo de diseño de estándar es siempre cero (vacío-base optimización es obligatorio)
Original:
The offset of the first member of a standard-layout type is always zero (vacío-base optimización is mandatory)
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] Posible implementación
#define offsetof(type,member) ((std::size_t) &(((type*)0)->member)) |
[editar] Ejemplo
Output:
the first element is at offset 0 the double is at offset 8
[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) | |
| (C++11) |
comprueba si un tipo es estándar de diseño de tipo Original: checks if a type is standard-layout type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (clase de plantilla) |