stddef.in.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
  2. Copyright (C) 2009-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. /* Written by Eric Blake. */
  14. /*
  15. * POSIX 2008 <stddef.h> for platforms that have issues.
  16. * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
  17. */
  18. #if __GNUC__ >= 3
  19. @PRAGMA_SYSTEM_HEADER@
  20. #endif
  21. @PRAGMA_COLUMNS@
  22. #if defined __need_wchar_t || defined __need_size_t \
  23. || defined __need_ptrdiff_t || defined __need_NULL \
  24. || defined __need_wint_t
  25. /* Special invocation convention inside gcc header files. In
  26. particular, gcc provides a version of <stddef.h> that blindly
  27. redefines NULL even when __need_wint_t was defined, even though
  28. wint_t is not normally provided by <stddef.h>. Hence, we must
  29. remember if special invocation has ever been used to obtain wint_t,
  30. in which case we need to clean up NULL yet again. */
  31. # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
  32. # ifdef __need_wint_t
  33. # define _GL_STDDEF_WINT_T
  34. # endif
  35. # @INCLUDE_NEXT@ @NEXT_STDDEF_H@
  36. /* On TinyCC, make sure that the macros that indicate the special invocation
  37. convention get undefined. */
  38. # undef __need_wchar_t
  39. # undef __need_size_t
  40. # undef __need_ptrdiff_t
  41. # undef __need_NULL
  42. # undef __need_wint_t
  43. # endif
  44. #else
  45. /* Normal invocation convention. */
  46. # ifndef _@GUARD_PREFIX@_STDDEF_H
  47. /* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a
  48. type with alignment 4, but 'long' has alignment 8. */
  49. # if defined _AIX && defined __LP64__
  50. # if !GNULIB_defined_max_align_t
  51. # ifdef _MAX_ALIGN_T
  52. /* /usr/include/stddef.h has already defined max_align_t. Override it. */
  53. typedef long rpl_max_align_t;
  54. # define max_align_t rpl_max_align_t
  55. # else
  56. /* Prevent /usr/include/stddef.h from defining max_align_t. */
  57. typedef long max_align_t;
  58. # define _MAX_ALIGN_T
  59. # endif
  60. # define GNULIB_defined_max_align_t 1
  61. # endif
  62. # endif
  63. /* The include_next requires a split double-inclusion guard. */
  64. # @INCLUDE_NEXT@ @NEXT_STDDEF_H@
  65. /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
  66. # if (@REPLACE_NULL@ \
  67. && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
  68. # undef NULL
  69. # ifdef __cplusplus
  70. /* ISO C++ says that the macro NULL must expand to an integer constant
  71. expression, hence '((void *) 0)' is not allowed in C++. */
  72. # if __GNUG__ >= 3
  73. /* GNU C++ has a __null macro that behaves like an integer ('int' or
  74. 'long') but has the same size as a pointer. Use that, to avoid
  75. warnings. */
  76. # define NULL __null
  77. # else
  78. # define NULL 0L
  79. # endif
  80. # else
  81. # define NULL ((void *) 0)
  82. # endif
  83. # endif
  84. # ifndef _@GUARD_PREFIX@_STDDEF_H
  85. # define _@GUARD_PREFIX@_STDDEF_H
  86. /* Some platforms lack wchar_t. */
  87. #if !@HAVE_WCHAR_T@
  88. # define wchar_t int
  89. #endif
  90. /* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is
  91. a hack in case the configure-time test was done with g++ even though
  92. we are currently compiling with gcc.
  93. On MSVC, max_align_t is defined only in C++ mode, after <cstddef> was
  94. included. Its definition is good since it has an alignment of 8 (on x86
  95. and x86_64).
  96. Similarly on OS/2 kLIBC. */
  97. #if (defined _MSC_VER || (defined __KLIBC__ && !defined __LIBCN__)) \
  98. && defined __cplusplus
  99. # include <cstddef>
  100. #else
  101. # if ! (@HAVE_MAX_ALIGN_T@ || (defined _GCC_MAX_ALIGN_T && !defined __clang__))
  102. # if !GNULIB_defined_max_align_t
  103. /* On the x86, the maximum storage alignment of double, long, etc. is 4,
  104. but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
  105. and the C11 standard allows this. Work around this problem by
  106. using __alignof__ (which returns 8 for double) rather than _Alignof
  107. (which returns 4), and align each union member accordingly. */
  108. # if defined __GNUC__ || (__clang_major__ >= 4)
  109. # define _GL_STDDEF_ALIGNAS(type) \
  110. __attribute__ ((__aligned__ (__alignof__ (type))))
  111. # else
  112. # define _GL_STDDEF_ALIGNAS(type) /* */
  113. # endif
  114. typedef union
  115. {
  116. char *__p _GL_STDDEF_ALIGNAS (char *);
  117. double __d _GL_STDDEF_ALIGNAS (double);
  118. long double __ld _GL_STDDEF_ALIGNAS (long double);
  119. long int __i _GL_STDDEF_ALIGNAS (long int);
  120. } rpl_max_align_t;
  121. # define max_align_t rpl_max_align_t
  122. # define GNULIB_defined_max_align_t 1
  123. # endif
  124. # endif
  125. #endif
  126. # endif /* _@GUARD_PREFIX@_STDDEF_H */
  127. # endif /* _@GUARD_PREFIX@_STDDEF_H */
  128. #endif /* __need_XXX */