offsetof
De cppreference.com
| Definido en el archivo de encabezado <stddef.h>
|
||
#define offsetof(type, member) /*definido-en-la-implementacion*/
|
||
La macro offsetof se expande a una expresión de constante entera del tipo size_t, cuyo valor es el offset, en bytes, desde el principio de un objeto de tipo especificado hasta su miembro especificado, incluyendo el relleno si lo hubiera.
Ejemplo
Ejecuta este código
#include <stdio.h>
#include <stddef.h>
struct S {
char c;
double d;
};
int main(void)
{
printf("el primer elemento está en el offset %zu\n", offsetof(struct S, c));
printf("el doble está en el offset %zu\n", offsetof(struct S, d));
}
Posible salida:
el primer elemento está en el offset 0
el doble está en el offset 8
Véase 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) | |
Documentación de C++ para offsetof
|