[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/types/offsetof [Back]  [Original]

offsetof cppreference.com
cppreference.com

offsetof

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++11)
(C++14)  
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)( C++20*)
(C++11)( C++20)
(C++11)
(C++17)
(C++11)(C++11)(C++11)
(C++11)( C++23)
(C++11)( C++23)
(C++11)
(C++11)
(C++17)

(C++11)( C++20*)(C++17)
 
<tbody> </tbody>
#define offsetof(type, member) /* */

offsetof std::size_t, , , .

o type , o.member lvalue, o. . , member , -, .

type PODType ( C++11) ( C++11), offsetof ( C++17) offsetof ( C++17).

offsetof(type, member) , type .

offsetof .

noexcept(offsetof(type, member)) true.

( C++11)

( ).

( C++11)

offsetof C++ : GCC, LLVM.

member . , . C DR 496.

C23 , offsetof , C++: offsetof(struct Foo { int a; }, a) ICC GCC, offsetof(struct Foo { int a, b; }, a) - Foo.

#include <cstddef>
#include <iostream>

struct S
{
    char   m0;
    double m1;
    short  m2;
    char   m3;
//  private: int z; // : 'S'    
};

int main()
{
    std::cout
        << " char   m0 = " << offsetof(S, m0) << '\n'
        << " double m1 = " << offsetof(S, m1) << '\n'
        << " short  m2 = " << offsetof(S, m2) << '\n'
        << " char   m3 = " << offsetof(S, m3) << '\n';
}

:

 char   m0 = 0
 double m1 = 8
 short  m2 = 16
 char   m3 = 18

C++:

CWG 273 C++98 offsetof , operator& ,
operator&
LWG 306 C++98 , type PODType
LWG 449 C++98 offsetof
LWG 306

, sizeof
( ) []
,
( ) []
C offsetof

Web Proxy Viewer  |  New URL  |  Original Page