stddef.h 1.5 KB

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