Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/**
40 * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
41 *
42 * @TYPE: The type of each flexible array element
43 * @NAME: The name of the flexible array member
44 *
45 * In order to have a flexible array member in a union or alone in a
46 * struct, it needs to be wrapped in an anonymous struct with at least 1
47 * named member, but that member can be empty.
48 */
49#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
50 struct { \
51 struct { } __empty_ ## NAME; \
52 TYPE NAME[]; \
53 }
54#endif