◐ Shell
clean mode source ↗

offsetof - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<cstddef>

#define offsetof(type, member) /*implementation-defined*/

Il offsetof macro restituisce una costante di std::size_t tipo, il cui valore è l'offset, in byte, dall'inizio di un oggetto del tipo specificato al suo membro specificato, compresi eventuali imbottiture.

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.

Note

Se type non è una norma di tipo-layout, il comportamento non è definito.

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.

Se member è un membro statico o un membro funzione, il comportamento non è definito.

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.

L'offset del primo membro di una norma-layout tipo è sempre zero (empty-base di ottimizzazione è obbligatorio)

Original:

The offset of the first member of a standard-layout type is always zero (empty-base di ottimizzazione is mandatory)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Possibile implementazione

#define offsetof(type,member) ((std::size_t) &(((type*)0)->member))

Esempio

#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';
}

Output:

the first element is at offset 0
the double is at offset 8

Vedi anche

senza segno tipo intero restituito dal gestore

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) [modifica]

controlla se è un tipo standard di layout 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.


(classe template) [modifica]