offsetof
Aus 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. |
definiert in Header <cstddef>
|
||
#define offsetof(type, member) /*implementation-defined*/ |
||
Die Makro offsetof expandiert zu einer Konstante vom Typ std::size_t, deren Wert von den Offset in Bytes vom Anfang eines Objekts der angegebenen Typs in ihren angegebenen Elements einschließlich der Polsterung gegebenenfalls .. ist
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.
Inhaltsverzeichnis |
[Bearbeiten] Notes
Wenn
type
nicht ein Standard-Layout-Typ, ist das Verhalten undefiniert .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.
Wenn
member
ein statisches Element oder ein Funktionselement ist, ist das Verhalten undefiniert .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.
Die des ersten Teils eines Standard-Tastaturbelegung Offset ist immer Null (empty-base-Optimierung ist obligatorisch)
Original:
The offset of the first member of a standard-layout type is always zero (empty-base-Optimierung 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.
[Bearbeiten] Mögliche Implementierung
#define offsetof(type,member) ((std::size_t) &(((type*)0)->member)) |
[Bearbeiten] Beispiel
#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
[Bearbeiten] Siehe auch
vorzeichenloser Ganzzahltyp, der vom Operator sizeof zurückgegeben wird 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) |
prüft, ob ein Typ ist Standard-Layout-Typ 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. (Klassen-Template) |