offsetof — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Déclaré dans l'en-tête <cstddef> |
||
|
|
||
offsetof la macro s'étend à une constante de std::size_t type, la valeur de ce qui est le décalage en octets du début d'un objet du type spécifié à son élément de donnée, y compris le cas échéant rembourrage .
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.
Notes
Si type n'est pas un type standard mise en page, le comportement est indéfini .
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.
Si member est un membre statique ou un membre de la fonction, le comportement est indéfini .
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.
Le décalage du premier membre d'un type standard-layout est toujours zéro (vide de base de l'optimisation est obligatoire)
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Mise en œuvre possible
#define offsetof(type,member) ((std::size_t) &(((type*)0)->member))
Exemple
#include <iostream> #include <cstddef> struct S { char c; double d; }; int main() { std::cout << "the first element is at offset " << offsetof(S, c) << '\n' << "the double is at offset " << offsetof(S, d) << '\n'; }
Résultat :
the first element is at offset 0 the double is at offset 8
Voir aussi
unsigned integer retournée par l'opérateur sizeofOriginal: The text has been machine-translated via Google Translate. (typedef) [edit] | |
vérifie si un type est standard disposition type Original: checks if a type is standard-layout type The text has been machine-translated via Google Translate. (classe générique) [edit] | |