stddef.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef __STDDEF_H
  26. #define __STDDEF_H
  27. #if !defined(_PTRDIFF_T) || __has_feature(modules)
  28. /* Always define ptrdiff_t when modules are available. */
  29. #if !__has_feature(modules)
  30. #define _PTRDIFF_T
  31. #endif
  32. typedef __PTRDIFF_TYPE__ ptrdiff_t;
  33. #endif
  34. #if !defined(_SIZE_T) || __has_feature(modules)
  35. /* Always define size_t when modules are available. */
  36. #if !__has_feature(modules)
  37. #define _SIZE_T
  38. #endif
  39. typedef __SIZE_TYPE__ size_t;
  40. #endif
  41. /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
  42. * enabled. */
  43. #if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \
  44. !defined(_RSIZE_T)) || __has_feature(modules)
  45. /* Always define rsize_t when modules are available. */
  46. #if !__has_feature(modules)
  47. #define _RSIZE_T
  48. #endif
  49. typedef __SIZE_TYPE__ rsize_t;
  50. #endif
  51. #ifndef __cplusplus
  52. /* Always define wchar_t when modules are available. */
  53. #if !defined(_WCHAR_T) || __has_feature(modules)
  54. #if !__has_feature(modules)
  55. #define _WCHAR_T
  56. #if defined(_MSC_EXTENSIONS)
  57. #define _WCHAR_T_DEFINED
  58. #endif
  59. #endif
  60. typedef __WCHAR_TYPE__ wchar_t;
  61. #endif
  62. #endif
  63. #undef NULL
  64. #ifdef __cplusplus
  65. # if !defined(__MINGW32__) && !defined(_MSC_VER)
  66. # define NULL __null
  67. # else
  68. # define NULL 0
  69. # endif
  70. #else
  71. # define NULL ((void*)0)
  72. #endif
  73. #ifdef __cplusplus
  74. #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
  75. namespace std { typedef decltype(nullptr) nullptr_t; }
  76. using ::std::nullptr_t;
  77. #endif
  78. #endif
  79. #define offsetof(t, d) __builtin_offsetof(t, d)
  80. #endif /* __STDDEF_H */
  81. /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
  82. __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
  83. #if defined(__need_wint_t)
  84. /* Always define wint_t when modules are available. */
  85. #if !defined(_WINT_T) || __has_feature(modules)
  86. #if !__has_feature(modules)
  87. #define _WINT_T
  88. #endif
  89. typedef __WINT_TYPE__ wint_t;
  90. #endif
  91. #undef __need_wint_t
  92. #endif /* __need_wint_t */