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. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <cstddef>
|
||
#define offsetof(type, member) /*implementation-defined*/ |
||
offsetof la macro s'tend une constante de std::size_t type, la valeur de ce qui est le dcalage en octets du dbut d'un objet du type spcifi son lment de donne, y compris le cas chant 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.
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 indfini .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 est un membre statique ou un membre de la fonction, le comportement est indfini .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.
Le dcalage du premier membre d'un type standard-layout est toujours zro (vide de base de l'optimisation est obligatoire)
Original:
The offset of the first member of a standard-layout type is always zero (vide de base de l'optimisation 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.
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';
}
Rsultat :
the first element is at offset 0
the double is at offset 8
Voir aussi
unsigned integer retourne par l'oprateur 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) |
vrifie 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. You can help to correct and verify the translation. Click here for instructions. (classe gnrique) |