stddef.h 13 KB

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