diff options
Diffstat (limited to 'clang/docs/LanguageExtensions.rst')
-rw-r--r-- | clang/docs/LanguageExtensions.rst | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 9b39dc2..dbec1cd 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -2360,6 +2360,50 @@ evaluated, so any side effects of the expression will be discarded. Query for this feature with ``__has_builtin(__builtin_assume)``. +``__builtin_offsetof`` +---------------------- + +``__builtin_offsetof`` is used to implement the ``offsetof`` macro, which +calculates the offset (in bytes) to a given member of the given type. + +**Syntax**: + +.. code-block:: c++ + + __builtin_offsetof(type-name, member-designator) + +**Example of Use**: + +.. code-block:: c++ + + struct S { + char c; + int i; + struct T { + float f[2]; + } t; + }; + + const int offset_to_i = __builtin_offsetof(struct S, i); + const int ext1 = __builtin_offsetof(struct U { int i; }, i); // C extension + const int ext2 = __builtin_offsetof(struct S, t.f[1]); // C & C++ extension + +**Description**: + +This builtin is usable in an integer constant expression which returns a value +of type ``size_t``. The value returned is the offset in bytes to the subobject +designated by the member-designator from the beginning of an object of type +``type-name``. Clang extends the required standard functionality in a few ways: + +* In C language modes, the first argument may be the definition of a new type. + Any type declared this way is scoped to the nearest scope containing the call + to the builtin. +* The second argument may be a member-designator designated by a series of + member access expressions using the dot (``.``) operator or array subscript + expressions. + +Query for this feature with ``__has_builtin(__builtin_offsetof)``. + ``__builtin_call_with_static_chain`` ------------------------------------ |