]>
Commit | Line | Data |
---|---|---|
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 | ||
10 | Support for offsetof | |
11 | ******************** | |
12 | ||
13 | GCC implements for both C and C++ a syntactic extension to implement | |
14 | the ``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 | ||
26 | This extension is sufficient such that | |
27 | ||
28 | .. code-block:: c++ | |
29 | ||
30 | #define offsetof(type, member) __builtin_offsetof (type, member) | |
31 | ||
32 | is a suitable definition of the ``offsetof`` macro. In C++, :samp:`{type}` | |
33 | may be dependent. In either case, :samp:`{member}` may consist of a single | |
3ed1b4ce | 34 | identifier, or a sequence of member accesses and array references. |