stddef.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. #include_next <stddef.h>
  2. /* Copyright (C) 1989-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /*
  20. * ISO C Standard: 7.17 Common definitions <stddef.h>
  21. */
  22. #if (!defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_ANSI_STDDEF_H) \
  23. && !defined(__STDDEF_H__)) \
  24. || defined(__need_wchar_t) || defined(__need_size_t) \
  25. || defined(__need_ptrdiff_t) || defined(__need_NULL) \
  26. || defined(__need_wint_t)
  27. /* Any one of these symbols __need_* means that GNU libc
  28. wants us just to define one data type. So don't define
  29. the symbols that indicate this file's entire job has been done. */
  30. #if (!defined(__need_wchar_t) && !defined(__need_size_t) \
  31. && !defined(__need_ptrdiff_t) && !defined(__need_NULL) \
  32. && !defined(__need_wint_t))
  33. #define _STDDEF_H
  34. #define _STDDEF_H_
  35. /* snaroff@next.com says the NeXT needs this. */
  36. #define _ANSI_STDDEF_H
  37. #endif
  38. #ifndef __sys_stdtypes_h
  39. /* This avoids lossage on SunOS but only if stdtypes.h comes first.
  40. There's no way to win with the other order! Sun lossage. */
  41. #if defined(__NetBSD__)
  42. #include <machine/ansi.h>
  43. #endif
  44. #if defined (__FreeBSD__)
  45. #include <sys/_types.h>
  46. #endif
  47. #if defined(__NetBSD__)
  48. #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_)
  49. #define _SIZE_T
  50. #endif
  51. #if !defined(_PTRDIFF_T_) && !defined(_BSD_PTRDIFF_T_)
  52. #define _PTRDIFF_T
  53. #endif
  54. /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
  55. instead of _WCHAR_T_. */
  56. #if !defined(_WCHAR_T_) && !defined(_BSD_WCHAR_T_)
  57. #ifndef _BSD_WCHAR_T_
  58. #define _WCHAR_T
  59. #endif
  60. #endif
  61. /* Undef _FOO_T_ if we are supposed to define foo_t. */
  62. #if defined (__need_ptrdiff_t) || defined (_STDDEF_H_)
  63. #undef _PTRDIFF_T_
  64. #undef _BSD_PTRDIFF_T_
  65. #endif
  66. #if defined (__need_size_t) || defined (_STDDEF_H_)
  67. #undef _SIZE_T_
  68. #undef _BSD_SIZE_T_
  69. #endif
  70. #if defined (__need_wchar_t) || defined (_STDDEF_H_)
  71. #undef _WCHAR_T_
  72. #undef _BSD_WCHAR_T_
  73. #endif
  74. #endif /* defined(__NetBSD__) */
  75. /* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
  76. Just ignore it. */
  77. #if defined (__sequent__) && defined (_PTRDIFF_T_)
  78. #undef _PTRDIFF_T_
  79. #endif
  80. /* On VxWorks, <type/vxTypesBase.h> may have defined macros like
  81. _TYPE_size_t which will typedef size_t. fixincludes patched the
  82. vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
  83. not defined, and so that defining this macro defines _GCC_SIZE_T.
  84. If we find that the macros are still defined at this point, we must
  85. invoke them so that the type is defined as expected. */
  86. #if defined (_TYPE_ptrdiff_t) && (defined (__need_ptrdiff_t) || defined (_STDDEF_H_))
  87. _TYPE_ptrdiff_t;
  88. #undef _TYPE_ptrdiff_t
  89. #endif
  90. #if defined (_TYPE_size_t) && (defined (__need_size_t) || defined (_STDDEF_H_))
  91. _TYPE_size_t;
  92. #undef _TYPE_size_t
  93. #endif
  94. #if defined (_TYPE_wchar_t) && (defined (__need_wchar_t) || defined (_STDDEF_H_))
  95. _TYPE_wchar_t;
  96. #undef _TYPE_wchar_t
  97. #endif
  98. /* In case nobody has defined these types, but we aren't running under
  99. GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and
  100. __WCHAR_TYPE__ have reasonable values. This can happen if the
  101. parts of GCC is compiled by an older compiler, that actually
  102. include gstddef.h, such as collect2. */
  103. /* Signed type of difference of two pointers. */
  104. /* Define this type if we are doing the whole job,
  105. or if we want this type in particular. */
  106. #if defined (_STDDEF_H) || defined (__need_ptrdiff_t)
  107. #ifndef _PTRDIFF_T /* in case <sys/types.h> has defined it. */
  108. #ifndef _T_PTRDIFF_
  109. #ifndef _T_PTRDIFF
  110. #ifndef __PTRDIFF_T
  111. #ifndef _PTRDIFF_T_
  112. #ifndef _BSD_PTRDIFF_T_
  113. #ifndef ___int_ptrdiff_t_h
  114. #ifndef _GCC_PTRDIFF_T
  115. #ifndef _PTRDIFF_T_DECLARED /* DragonFly */
  116. #ifndef __DEFINED_ptrdiff_t /* musl libc */
  117. #define _PTRDIFF_T
  118. #define _T_PTRDIFF_
  119. #define _T_PTRDIFF
  120. #define __PTRDIFF_T
  121. #define _PTRDIFF_T_
  122. #define _BSD_PTRDIFF_T_
  123. #define ___int_ptrdiff_t_h
  124. #define _GCC_PTRDIFF_T
  125. #define _PTRDIFF_T_DECLARED
  126. #define __DEFINED_ptrdiff_t
  127. #ifndef __PTRDIFF_TYPE__
  128. #define __PTRDIFF_TYPE__ long int
  129. #endif
  130. typedef __PTRDIFF_TYPE__ ptrdiff_t;
  131. #endif /* __DEFINED_ptrdiff_t */
  132. #endif /* _PTRDIFF_T_DECLARED */
  133. #endif /* _GCC_PTRDIFF_T */
  134. #endif /* ___int_ptrdiff_t_h */
  135. #endif /* _BSD_PTRDIFF_T_ */
  136. #endif /* _PTRDIFF_T_ */
  137. #endif /* __PTRDIFF_T */
  138. #endif /* _T_PTRDIFF */
  139. #endif /* _T_PTRDIFF_ */
  140. #endif /* _PTRDIFF_T */
  141. /* If this symbol has done its job, get rid of it. */
  142. #undef __need_ptrdiff_t
  143. #endif /* _STDDEF_H or __need_ptrdiff_t. */
  144. /* Unsigned type of `sizeof' something. */
  145. /* Define this type if we are doing the whole job,
  146. or if we want this type in particular. */
  147. #if defined (_STDDEF_H) || defined (__need_size_t)
  148. #ifndef __size_t__ /* BeOS */
  149. #ifndef __SIZE_T__ /* Cray Unicos/Mk */
  150. #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
  151. #ifndef _SYS_SIZE_T_H
  152. #ifndef _T_SIZE_
  153. #ifndef _T_SIZE
  154. #ifndef __SIZE_T
  155. #ifndef _SIZE_T_
  156. #ifndef _BSD_SIZE_T_
  157. #ifndef _SIZE_T_DEFINED_
  158. #ifndef _SIZE_T_DEFINED
  159. #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
  160. #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
  161. #ifndef __DEFINED_size_t /* musl libc */
  162. #ifndef ___int_size_t_h
  163. #ifndef _GCC_SIZE_T
  164. #ifndef _SIZET_
  165. #ifndef __size_t
  166. #define __size_t__ /* BeOS */
  167. #define __SIZE_T__ /* Cray Unicos/Mk */
  168. #define _SIZE_T
  169. #define _SYS_SIZE_T_H
  170. #define _T_SIZE_
  171. #define _T_SIZE
  172. #define __SIZE_T
  173. #define _SIZE_T_
  174. #define _BSD_SIZE_T_
  175. #define _SIZE_T_DEFINED_
  176. #define _SIZE_T_DEFINED
  177. #define _BSD_SIZE_T_DEFINED_ /* Darwin */
  178. #define _SIZE_T_DECLARED /* FreeBSD 5 */
  179. #define __DEFINED_size_t /* musl libc */
  180. #define ___int_size_t_h
  181. #define _GCC_SIZE_T
  182. #define _SIZET_
  183. #if defined (__FreeBSD__) \
  184. || defined(__DragonFly__) \
  185. || defined(__FreeBSD_kernel__) \
  186. || defined(__VMS__)
  187. /* __size_t is a typedef, must not trash it. */
  188. #else
  189. #define __size_t
  190. #endif
  191. #ifndef __SIZE_TYPE__
  192. #define __SIZE_TYPE__ long unsigned int
  193. #endif
  194. #if !(defined (__GNUG__) && defined (size_t))
  195. typedef __SIZE_TYPE__ size_t;
  196. #ifdef __BEOS__
  197. typedef long ssize_t;
  198. #endif /* __BEOS__ */
  199. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  200. #endif /* __size_t */
  201. #endif /* _SIZET_ */
  202. #endif /* _GCC_SIZE_T */
  203. #endif /* ___int_size_t_h */
  204. #endif /* __DEFINED_size_t */
  205. #endif /* _SIZE_T_DECLARED */
  206. #endif /* _BSD_SIZE_T_DEFINED_ */
  207. #endif /* _SIZE_T_DEFINED */
  208. #endif /* _SIZE_T_DEFINED_ */
  209. #endif /* _BSD_SIZE_T_ */
  210. #endif /* _SIZE_T_ */
  211. #endif /* __SIZE_T */
  212. #endif /* _T_SIZE */
  213. #endif /* _T_SIZE_ */
  214. #endif /* _SYS_SIZE_T_H */
  215. #endif /* _SIZE_T */
  216. #endif /* __SIZE_T__ */
  217. #endif /* __size_t__ */
  218. #undef __need_size_t
  219. #endif /* _STDDEF_H or __need_size_t. */
  220. /* Wide character type.
  221. Locale-writers should change this as necessary to
  222. be big enough to hold unique values not between 0 and 127,
  223. and not (wchar_t) -1, for each defined multibyte character. */
  224. /* Define this type if we are doing the whole job,
  225. or if we want this type in particular. */
  226. #if defined (_STDDEF_H) || defined (__need_wchar_t)
  227. #ifndef __wchar_t__ /* BeOS */
  228. #ifndef __WCHAR_T__ /* Cray Unicos/Mk */
  229. #ifndef _WCHAR_T
  230. #ifndef _T_WCHAR_
  231. #ifndef _T_WCHAR
  232. #ifndef __WCHAR_T
  233. #ifndef _WCHAR_T_
  234. #ifndef _BSD_WCHAR_T_
  235. #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */
  236. #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */
  237. #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */
  238. #ifndef __DEFINED_wchar_t /* musl libc */
  239. #ifndef _WCHAR_T_DEFINED_
  240. #ifndef _WCHAR_T_DEFINED
  241. #ifndef _WCHAR_T_H
  242. #ifndef ___int_wchar_t_h
  243. #ifndef __INT_WCHAR_T_H
  244. #ifndef _GCC_WCHAR_T
  245. #define __wchar_t__ /* BeOS */
  246. #define __WCHAR_T__ /* Cray Unicos/Mk */
  247. #define _WCHAR_T
  248. #define _T_WCHAR_
  249. #define _T_WCHAR
  250. #define __WCHAR_T
  251. #define _WCHAR_T_
  252. #define _BSD_WCHAR_T_
  253. #define _WCHAR_T_DEFINED_
  254. #define _WCHAR_T_DEFINED
  255. #define _WCHAR_T_H
  256. #define ___int_wchar_t_h
  257. #define __INT_WCHAR_T_H
  258. #define _GCC_WCHAR_T
  259. #define _WCHAR_T_DECLARED
  260. #define __DEFINED_wchar_t
  261. /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
  262. instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other
  263. symbols in the _FOO_T_ family, stays defined even after its
  264. corresponding type is defined). If we define wchar_t, then we
  265. must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if
  266. we undef _WCHAR_T_, then we must also define rune_t, since
  267. headers like runetype.h assume that if machine/ansi.h is included,
  268. and _BSD_WCHAR_T_ is not defined, then rune_t is available.
  269. machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of
  270. the same type." */
  271. #ifdef _BSD_WCHAR_T_
  272. #undef _BSD_WCHAR_T_
  273. #ifdef _BSD_RUNE_T_
  274. #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
  275. typedef _BSD_RUNE_T_ rune_t;
  276. #define _BSD_WCHAR_T_DEFINED_
  277. #define _BSD_RUNE_T_DEFINED_ /* Darwin */
  278. #if defined (__FreeBSD__) && (__FreeBSD__ < 5)
  279. /* Why is this file so hard to maintain properly? In contrast to
  280. the comment above regarding BSD/386 1.1, on FreeBSD for as long
  281. as the symbol has existed, _BSD_RUNE_T_ must not stay defined or
  282. redundant typedefs will occur when stdlib.h is included after this file. */
  283. #undef _BSD_RUNE_T_
  284. #endif
  285. #endif
  286. #endif
  287. #endif
  288. /* FreeBSD 5 can't be handled well using "traditional" logic above
  289. since it no longer defines _BSD_RUNE_T_ yet still desires to export
  290. rune_t in some cases... */
  291. #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
  292. #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
  293. #if __BSD_VISIBLE
  294. #ifndef _RUNE_T_DECLARED
  295. typedef __rune_t rune_t;
  296. #define _RUNE_T_DECLARED
  297. #endif
  298. #endif
  299. #endif
  300. #endif
  301. #ifndef __WCHAR_TYPE__
  302. #define __WCHAR_TYPE__ int
  303. #endif
  304. #ifndef __cplusplus
  305. typedef __WCHAR_TYPE__ wchar_t;
  306. #endif
  307. #endif
  308. #endif
  309. #endif
  310. #endif
  311. #endif
  312. #endif
  313. #endif /* __DEFINED_wchar_t */
  314. #endif /* _WCHAR_T_DECLARED */
  315. #endif /* _BSD_RUNE_T_DEFINED_ */
  316. #endif
  317. #endif
  318. #endif
  319. #endif
  320. #endif
  321. #endif
  322. #endif
  323. #endif /* __WCHAR_T__ */
  324. #endif /* __wchar_t__ */
  325. #undef __need_wchar_t
  326. #endif /* _STDDEF_H or __need_wchar_t. */
  327. #if defined (__need_wint_t)
  328. #ifndef _WINT_T
  329. #define _WINT_T
  330. #ifndef __WINT_TYPE__
  331. #define __WINT_TYPE__ unsigned int
  332. #endif
  333. typedef __WINT_TYPE__ wint_t;
  334. #endif
  335. #undef __need_wint_t
  336. #endif
  337. #if defined(__NetBSD__)
  338. /* The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
  339. are probably typos and should be removed before 2.8 is released. */
  340. #ifdef _GCC_PTRDIFF_T_
  341. #undef _PTRDIFF_T_
  342. #undef _BSD_PTRDIFF_T_
  343. #endif
  344. #ifdef _GCC_SIZE_T_
  345. #undef _SIZE_T_
  346. #undef _BSD_SIZE_T_
  347. #endif
  348. #ifdef _GCC_WCHAR_T_
  349. #undef _WCHAR_T_
  350. #undef _BSD_WCHAR_T_
  351. #endif
  352. /* The following ones are the real ones. */
  353. #ifdef _GCC_PTRDIFF_T
  354. #undef _PTRDIFF_T_
  355. #undef _BSD_PTRDIFF_T_
  356. #endif
  357. #ifdef _GCC_SIZE_T
  358. #undef _SIZE_T_
  359. #undef _BSD_SIZE_T_
  360. #endif
  361. #ifdef _GCC_WCHAR_T
  362. #undef _WCHAR_T_
  363. #undef _BSD_WCHAR_T_
  364. #endif
  365. #endif /* __NetBSD__ */
  366. #endif /* __sys_stdtypes_h */
  367. /* A null pointer constant. */
  368. #if defined (_STDDEF_H) || defined (__need_NULL)
  369. #undef NULL /* in case <stdio.h> has defined it. */
  370. #ifdef __GNUG__
  371. #define NULL __null
  372. #else /* G++ */
  373. #ifndef __cplusplus
  374. #define NULL ((void *)0)
  375. #else /* C++ */
  376. #define NULL 0
  377. #endif /* C++ */
  378. #endif /* G++ */
  379. #endif /* NULL not defined and <stddef.h> or need NULL. */
  380. #undef __need_NULL
  381. #ifdef _STDDEF_H
  382. /* Offset of member MEMBER in a struct of type TYPE. */
  383. #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
  384. #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
  385. || (defined(__cplusplus) && __cplusplus >= 201103L)
  386. #ifndef _GCC_MAX_ALIGN_T
  387. #define _GCC_MAX_ALIGN_T
  388. /* Type whose alignment is supported in every context and is at least
  389. as great as that of any standard type not using alignment
  390. specifiers. */
  391. typedef struct {
  392. long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
  393. long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
  394. /* _Float128 is defined as a basic type, so max_align_t must be
  395. sufficiently aligned for it. This code must work in C++, so we
  396. use __float128 here; that is only available on some
  397. architectures, but only on i386 is extra alignment needed for
  398. __float128. */
  399. #ifdef __i386__
  400. __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128))));
  401. #endif
  402. } max_align_t;
  403. #endif
  404. #endif /* C11 or C++11. */
  405. #if defined(__cplusplus) && __cplusplus >= 201103L
  406. #ifndef _GXX_NULLPTR_T
  407. #define _GXX_NULLPTR_T
  408. typedef decltype(nullptr) nullptr_t;
  409. #endif
  410. #endif /* C++11. */
  411. #endif /* _STDDEF_H was defined this time */
  412. #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__
  413. || __need_XXX was not defined before */