1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
2 | #ifndef _LINUX_STDDEF_H |
3 | #define _LINUX_STDDEF_H |
4 | |
5 | |
6 | |
7 | #ifndef __always_inline |
8 | #define __always_inline __inline__ |
9 | #endif |
10 | |
11 | /* Not all C++ standards support type declarations inside an anonymous union */ |
12 | #ifndef __cplusplus |
13 | #define __struct_group_tag(TAG) TAG |
14 | #else |
15 | #define __struct_group_tag(TAG) |
16 | #endif |
17 | |
18 | /** |
19 | * __struct_group() - Create a mirrored named and anonyomous struct |
20 | * |
21 | * @TAG: The tag name for the named sub-struct (usually empty) |
22 | * @NAME: The identifier name of the mirrored sub-struct |
23 | * @ATTRS: Any struct attributes (usually empty) |
24 | * @MEMBERS: The member declarations for the mirrored structs |
25 | * |
26 | * Used to create an anonymous union of two structs with identical layout |
27 | * and size: one anonymous and one named. The former's members can be used |
28 | * normally without sub-struct naming, and the latter can be used to |
29 | * reason about the start, end, and size of the group of struct members. |
30 | * The named struct can also be explicitly tagged for layer reuse (C only), |
31 | * as well as both having struct attributes appended. |
32 | */ |
33 | #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ |
34 | union { \ |
35 | struct { MEMBERS } ATTRS; \ |
36 | struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \ |
37 | } ATTRS |
38 | |
39 | #ifdef __cplusplus |
40 | /* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ |
41 | #define __DECLARE_FLEX_ARRAY(T, member) \ |
42 | T member[0] |
43 | #else |
44 | /** |
45 | * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union |
46 | * |
47 | * @TYPE: The type of each flexible array element |
48 | * @NAME: The name of the flexible array member |
49 | * |
50 | * In order to have a flexible array member in a union or alone in a |
51 | * struct, it needs to be wrapped in an anonymous struct with at least 1 |
52 | * named member, but that member can be empty. |
53 | */ |
54 | #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ |
55 | struct { \ |
56 | struct { } __empty_ ## NAME; \ |
57 | TYPE NAME[]; \ |
58 | } |
59 | #endif |
60 | |
61 | #ifndef __counted_by |
62 | #define __counted_by(m) |
63 | #endif |
64 | |
65 | #endif /* _LINUX_STDDEF_H */ |
66 | |