xref: /openbmc/linux/include/uapi/linux/stddef.h (revision 3080ea55)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2d1515582SWill Deacon #include <linux/compiler_types.h>
3283d7573SDenys Vlasenko 
4283d7573SDenys Vlasenko #ifndef __always_inline
5283d7573SDenys Vlasenko #define __always_inline inline
6283d7573SDenys Vlasenko #endif
750d7bd38SKees Cook 
850d7bd38SKees Cook /**
950d7bd38SKees Cook  * __struct_group() - Create a mirrored named and anonyomous struct
1050d7bd38SKees Cook  *
1150d7bd38SKees Cook  * @TAG: The tag name for the named sub-struct (usually empty)
1250d7bd38SKees Cook  * @NAME: The identifier name of the mirrored sub-struct
1350d7bd38SKees Cook  * @ATTRS: Any struct attributes (usually empty)
1450d7bd38SKees Cook  * @MEMBERS: The member declarations for the mirrored structs
1550d7bd38SKees Cook  *
1650d7bd38SKees Cook  * Used to create an anonymous union of two structs with identical layout
1750d7bd38SKees Cook  * and size: one anonymous and one named. The former's members can be used
1850d7bd38SKees Cook  * normally without sub-struct naming, and the latter can be used to
1950d7bd38SKees Cook  * reason about the start, end, and size of the group of struct members.
2050d7bd38SKees Cook  * The named struct can also be explicitly tagged for layer reuse, as well
2150d7bd38SKees Cook  * as both having struct attributes appended.
2250d7bd38SKees Cook  */
2350d7bd38SKees Cook #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
2450d7bd38SKees Cook 	union { \
2550d7bd38SKees Cook 		struct { MEMBERS } ATTRS; \
2650d7bd38SKees Cook 		struct TAG { MEMBERS } ATTRS NAME; \
2750d7bd38SKees Cook 	}
28*3080ea55SKees Cook 
29*3080ea55SKees Cook /**
30*3080ea55SKees Cook  * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
31*3080ea55SKees Cook  *
32*3080ea55SKees Cook  * @TYPE: The type of each flexible array element
33*3080ea55SKees Cook  * @NAME: The name of the flexible array member
34*3080ea55SKees Cook  *
35*3080ea55SKees Cook  * In order to have a flexible array member in a union or alone in a
36*3080ea55SKees Cook  * struct, it needs to be wrapped in an anonymous struct with at least 1
37*3080ea55SKees Cook  * named member, but that member can be empty.
38*3080ea55SKees Cook  */
39*3080ea55SKees Cook #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
40*3080ea55SKees Cook 	struct { \
41*3080ea55SKees Cook 		struct { } __empty_ ## NAME; \
42*3080ea55SKees Cook 		TYPE NAME[]; \
43*3080ea55SKees Cook 	}
44