stddef.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*===---- stddef.h - Basic type definitions --------------------------------===
  2. *
  3. * Copyright (c) 2008 Eli Friedman
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. *
  23. *===-----------------------------------------------------------------------===
  24. */
  25. #if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) || \
  26. defined(__need_size_t) || defined(__need_wchar_t) || \
  27. defined(__need_NULL) || defined(__need_wint_t)
  28. #if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
  29. !defined(__need_wchar_t) && !defined(__need_NULL) && \
  30. !defined(__need_wint_t)
  31. /* Always define miscellaneous pieces when modules are available. */
  32. #if !__has_feature(modules)
  33. #define __STDDEF_H
  34. #endif
  35. #define __need_ptrdiff_t
  36. #define __need_size_t
  37. #define __need_wchar_t
  38. #define __need_NULL
  39. #define __need_STDDEF_H_misc
  40. /* __need_wint_t is intentionally not defined here. */
  41. #endif
  42. #if defined(__need_ptrdiff_t)
  43. #if !defined(_PTRDIFF_T) || __has_feature(modules)
  44. /* Always define ptrdiff_t when modules are available. */
  45. #if !__has_feature(modules)
  46. #define _PTRDIFF_T
  47. #endif
  48. typedef __PTRDIFF_TYPE__ ptrdiff_t;
  49. #endif
  50. #undef __need_ptrdiff_t
  51. #endif /* defined(__need_ptrdiff_t) */
  52. #if defined(__need_size_t)
  53. #if !defined(_SIZE_T) || __has_feature(modules)
  54. /* Always define size_t when modules are available. */
  55. #if !__has_feature(modules)
  56. #define _SIZE_T
  57. #endif
  58. typedef __SIZE_TYPE__ size_t;
  59. #endif
  60. #undef __need_size_t
  61. #endif /*defined(__need_size_t) */
  62. #if defined(__need_STDDEF_H_misc)
  63. /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
  64. * enabled. */
  65. #if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \
  66. !defined(_RSIZE_T)) || __has_feature(modules)
  67. /* Always define rsize_t when modules are available. */
  68. #if !__has_feature(modules)
  69. #define _RSIZE_T
  70. #endif
  71. typedef __SIZE_TYPE__ rsize_t;
  72. #endif
  73. #endif /* defined(__need_STDDEF_H_misc) */
  74. #if defined(__need_wchar_t)
  75. #ifndef __cplusplus
  76. /* Always define wchar_t when modules are available. */
  77. #if !defined(_WCHAR_T) || __has_feature(modules)
  78. #if !__has_feature(modules)
  79. #define _WCHAR_T
  80. #if defined(_MSC_EXTENSIONS)
  81. #define _WCHAR_T_DEFINED
  82. #endif
  83. #endif
  84. typedef __WCHAR_TYPE__ wchar_t;
  85. #endif
  86. #endif
  87. #undef __need_wchar_t
  88. #endif /* defined(__need_wchar_t) */
  89. #if defined(__need_NULL)
  90. #undef NULL
  91. #ifdef __cplusplus
  92. # if !defined(__MINGW32__) && !defined(_MSC_VER)
  93. # define NULL __null
  94. # else
  95. # define NULL 0
  96. # endif
  97. #else
  98. # define NULL ((void*)0)
  99. #endif
  100. #ifdef __cplusplus
  101. #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
  102. namespace std { typedef decltype(nullptr) nullptr_t; }
  103. using ::std::nullptr_t;
  104. #endif
  105. #endif
  106. #undef __need_NULL
  107. #endif /* defined(__need_NULL) */
  108. #if defined(__need_STDDEF_H_misc)
  109. #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
  110. #include "__stddef_max_align_t.h"
  111. #endif
  112. #define offsetof(t, d) __builtin_offsetof(t, d)
  113. #undef __need_STDDEF_H_misc
  114. #endif /* defined(__need_STDDEF_H_misc) */
  115. /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
  116. __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
  117. #if defined(__need_wint_t)
  118. /* Always define wint_t when modules are available. */
  119. #if !defined(_WINT_T) || __has_feature(modules)
  120. #if !__has_feature(modules)
  121. #define _WINT_T
  122. #endif
  123. typedef __WINT_TYPE__ wint_t;
  124. #endif
  125. #undef __need_wint_t
  126. #endif /* __need_wint_t */
  127. #endif