]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gcc/extensions-to-the-c-language-family/support-for-offsetof.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gcc / extensions-to-the-c-language-family / support-for-offsetof.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: __builtin_offsetof
7
8.. _offsetof:
9
10Support for offsetof
11********************
12
13GCC implements for both C and C++ a syntactic extension to implement
14the ``offsetof`` macro.
15
16.. code-block:: c++
17
18 primary:
19 "__builtin_offsetof" "(" typename "," offsetof_member_designator ")"
20
21 offsetof_member_designator:
22 identifier
23 | offsetof_member_designator "." identifier
24 | offsetof_member_designator "[" expr "]"
25
26This extension is sufficient such that
27
28.. code-block:: c++
29
30 #define offsetof(type, member) __builtin_offsetof (type, member)
31
32is a suitable definition of the ``offsetof`` macro. In C++, :samp:`{type}`
33may be dependent. In either case, :samp:`{member}` may consist of a single
3ed1b4ce 34identifier, or a sequence of member accesses and array references.