offsetof

您所在的位置:网站首页 offseto offsetof

offsetof

#offsetof| 来源: 网络整理| 查看: 265

  C++ Compiler support Freestanding and hosted Language Standard library Standard library headers Named requirements Feature test macros (C++20) Language support library Concepts library (C++20) Metaprogramming library (C++11) Diagnostics library General utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Localizations library Input/output library Filesystem library (C++17) Regular expressions library (C++11) Concurrency support library (C++11) Technical specifications Symbols index External libraries [edit]  Utilities library Language support Type support (basic types, RTTI) Library feature-test macros (C++20) Dynamic memory management launder(C++17) Program utilities Coroutine support (C++20) Variadic functions is_constant_evaluated(C++20) initializer_list(C++11) source_location(C++20) Three-way comparison (C++20) three_way_comparablethree_way_comparable_with(C++20)(C++20) strong_ordering(C++20) weak_ordering(C++20) partial_ordering(C++20) common_comparison_category(C++20) compare_three_way_result(C++20) compare_three_way(C++20) strong_order(C++20) weak_order(C++20) partial_order(C++20) compare_strong_order_fallback(C++20) compare_weak_order_fallback(C++20) compare_partial_order_fallback(C++20)    is_eqis_neqis_ltis_lteqis_gtis_gteq(C++20)(C++20)(C++20)(C++20)(C++20)(C++20) General utilities Date and time Function objects Formatting library (C++20) bitset hash(C++11) Relational operators (deprecated in C++20) rel_ops::operator!=rel_ops::operator> rel_ops::operator= Integer comparison functions cmp_equalcmp_lesscmp_less_than(C++20)(C++20)(C++20)    cmp_not_equalcmp_greatercmp_greater_than(C++20)(C++20)(C++20) in_range(C++20) Swap and type operations swap ranges::swap(C++20) exchange(C++14) declval(C++11) to_underlying(C++23) forward(C++11) forward_like(C++23) move(C++11) move_if_noexcept(C++11) as_const(C++17) Common vocabulary types pair tuple(C++11) optional(C++17) any(C++17) variant(C++17) tuple_size(C++11) tuple_element(C++11) apply(C++17) make_from_tuple(C++17) expected(C++23) Elementary string conversions to_chars(C++17) from_chars(C++17) chars_format(C++17) [edit]  Type support Basic types Fixed width integer types (C++11) Fixed width floating-point types (C++23) ptrdiff_t size_t max_align_t(C++11)     byte(C++17) nullptr_t(C++11) offsetof NULL Numeric limits numeric_limits C numeric limits interface Runtime type information type_info type_index(C++11) bad_typeid bad_cast [edit]  Defined in header #define offsetof(type, member) /* implementation-defined */

The macro offsetof expands to an integral constant expression 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 subobject, including padding bits if any.

Given an object o of type type and static storage duration, o.member shall be an lvalue constant expression that refers to a subobject of o. Otherwise, the behavior is undefined. Particularly, if member is a static data member, a bit-field, or a member function, the behavior is undefined.

If type is not a PODType (until C++11)standard layout type (since C++11), the result of offsetof is undefined (until C++17)use of the offsetof macro is conditionally-supported (since C++17).

The expression offsetof(type, member) is never type-dependent and it is value-dependent if and only if type is dependent.

Contents 1 Exceptions 2 Notes 3 Example 4 Defect reports 5 See also [edit] Exceptions

offsetof throws no exceptions.

The expression noexcept(offsetof(type, member)) always evaluates to true.

(since C++11) [edit] Notes

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

(since C++11)

offsetof cannot be implemented in standard C++ and requires compiler support: GCC, LLVM.

member is not restricted to a direct member. It can denote a subobject of a given member, such as an element of an array member. This is specified by C DR 496.

It is specified in C23 that defining a new type in offsetof is undefined behavior, and such usage is only partially supported by some implementations in C++ modes: offsetof(struct Foo { int a; }, a) is supported by ICC and some old versions of GCC, while offsetof(struct Foo { int a, b; }, a) is rejected by all known implementations because of the comma in the definition of Foo.

[edit] Example Run this code #include #include   struct S { char m0; double m1; short m2; char m3; // private: int z; // warning: 'S' is a non-standard-layout type };   int main() { std::cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3