xref: /openbmc/linux/include/uapi/linux/stddef.h (revision 1b1f98dd)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #include <linux/compiler_types.h>
3 
4 #ifndef __always_inline
5 #define __always_inline inline
6 #endif
7 
8 /**
9  * __struct_group() - Create a mirrored named and anonyomous struct
10  *
11  * @TAG: The tag name for the named sub-struct (usually empty)
12  * @NAME: The identifier name of the mirrored sub-struct
13  * @ATTRS: Any struct attributes (usually empty)
14  * @MEMBERS: The member declarations for the mirrored structs
15  *
16  * Used to create an anonymous union of two structs with identical layout
17  * and size: one anonymous and one named. The former's members can be used
18  * normally without sub-struct naming, and the latter can be used to
19  * reason about the start, end, and size of the group of struct members.
20  * The named struct can also be explicitly tagged for layer reuse, as well
21  * as both having struct attributes appended.
22  */
23 #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
24 	union { \
25 		struct { MEMBERS } ATTRS; \
26 		struct TAG { MEMBERS } ATTRS NAME; \
27 	}
28 
29 /**
30  * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
31  *
32  * @TYPE: The type of each flexible array element
33  * @NAME: The name of the flexible array member
34  *
35  * In order to have a flexible array member in a union or alone in a
36  * struct, it needs to be wrapped in an anonymous struct with at least 1
37  * named member, but that member can be empty.
38  */
39 #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
40 	struct { \
41 		struct { } __empty_ ## NAME; \
42 		TYPE NAME[]; \
43 	}
44