offsetof
提供: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. |
| Defined in header <cstddef>
|
||
| #define offsetof(type, member) /*implementation-defined*/ |
||
マクロoffsetofはstd::size_t型の定数に展開され、値が指定された型のオブジェクトの先頭から、もしあればパディングを含め、指定したメンバーに、バイト単位でオフセットされます.
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.
目次 |
[編集] ノート
typeは、標準レイアウト型でない場合、動作は未定義です.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.
memberは静的メンバあるいは関数メンバである場合、動作は未定義です.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.
標準レイアウトの種類の最初のメンバのオフセット(空のベース最適化必須です)は常にゼロです
Original:
The offset of the first member of a standard-layout type is always zero (空のベース最適化 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.
[編集] 可能な実装
#define offsetof(type,member) ((std::size_t) &(((type*)0)->member)) |
[編集] 例
Output:
the first element is at offset 0 the double is at offset 8
[編集] も参照してください
| 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) |
タイプかどうかをチェックするには、標準レイアウトタイプです 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. (クラステンプレート) |