2
0

stddef.h 2.1 KB

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