xref: /openbmc/linux/include/uapi/linux/stddef.h (revision 32a4ec21)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
255037ed7STadeusz Struk #ifndef _UAPI_LINUX_STDDEF_H
355037ed7STadeusz Struk #define _UAPI_LINUX_STDDEF_H
455037ed7STadeusz Struk 
5d1515582SWill Deacon #include <linux/compiler_types.h>
6283d7573SDenys Vlasenko 
7283d7573SDenys Vlasenko #ifndef __always_inline
8283d7573SDenys Vlasenko #define __always_inline inline
9283d7573SDenys Vlasenko #endif
1050d7bd38SKees Cook 
1150d7bd38SKees Cook /**
1250d7bd38SKees Cook  * __struct_group() - Create a mirrored named and anonyomous struct
1350d7bd38SKees Cook  *
1450d7bd38SKees Cook  * @TAG: The tag name for the named sub-struct (usually empty)
1550d7bd38SKees Cook  * @NAME: The identifier name of the mirrored sub-struct
1650d7bd38SKees Cook  * @ATTRS: Any struct attributes (usually empty)
1750d7bd38SKees Cook  * @MEMBERS: The member declarations for the mirrored structs
1850d7bd38SKees Cook  *
1950d7bd38SKees Cook  * Used to create an anonymous union of two structs with identical layout
2050d7bd38SKees Cook  * and size: one anonymous and one named. The former's members can be used
2150d7bd38SKees Cook  * normally without sub-struct naming, and the latter can be used to
2250d7bd38SKees Cook  * reason about the start, end, and size of the group of struct members.
2350d7bd38SKees Cook  * The named struct can also be explicitly tagged for layer reuse, as well
2450d7bd38SKees Cook  * as both having struct attributes appended.
2550d7bd38SKees Cook  */
2650d7bd38SKees Cook #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
2750d7bd38SKees Cook 	union { \
2850d7bd38SKees Cook 		struct { MEMBERS } ATTRS; \
2950d7bd38SKees Cook 		struct TAG { MEMBERS } ATTRS NAME; \
3050d7bd38SKees Cook 	}
313080ea55SKees Cook 
32*32a4ec21SAlexey Dobriyan #ifdef __cplusplus
33*32a4ec21SAlexey Dobriyan /* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */
34*32a4ec21SAlexey Dobriyan #define __DECLARE_FLEX_ARRAY(T, member)	\
35*32a4ec21SAlexey Dobriyan 	T member[0]
36*32a4ec21SAlexey Dobriyan #else
373080ea55SKees Cook /**
383080ea55SKees Cook  * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
393080ea55SKees Cook  *
403080ea55SKees Cook  * @TYPE: The type of each flexible array element
413080ea55SKees Cook  * @NAME: The name of the flexible array member
423080ea55SKees Cook  *
433080ea55SKees Cook  * In order to have a flexible array member in a union or alone in a
443080ea55SKees Cook  * struct, it needs to be wrapped in an anonymous struct with at least 1
453080ea55SKees Cook  * named member, but that member can be empty.
463080ea55SKees Cook  */
473080ea55SKees Cook #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
483080ea55SKees Cook 	struct { \
493080ea55SKees Cook 		struct { } __empty_ ## NAME; \
503080ea55SKees Cook 		TYPE NAME[]; \
513080ea55SKees Cook 	}
52*32a4ec21SAlexey Dobriyan #endif
53c8248fafSKees Cook 
54c8248fafSKees Cook #ifndef __counted_by
55c8248fafSKees Cook #define __counted_by(m)
56c8248fafSKees Cook #endif
57531108ecSAlexey Dobriyan 
58531108ecSAlexey Dobriyan #endif /* _UAPI_LINUX_STDDEF_H */
59