stddef.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* Copyright (C) 1989-2015 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. /* On 4.3bsd-net2, make sure ansi.h is included, so we have
  41. one less case to deal with in the following. */
  42. #if defined (__BSD_NET2__) || defined (____386BSD____) || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) || defined(__NetBSD__)
  43. #include <machine/ansi.h>
  44. #endif
  45. /* On FreeBSD 5, machine/ansi.h does not exist anymore... */
  46. #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
  47. #include <sys/_types.h>
  48. #endif
  49. /* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are
  50. defined if the corresponding type is *not* defined.
  51. FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_.
  52. NetBSD defines _I386_ANSI_H_ and _X86_64_ANSI_H_ instead of _ANSI_H_ */
  53. #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_)
  54. #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_)
  55. #define _SIZE_T
  56. #endif
  57. #if !defined(_PTRDIFF_T_) && !defined(_BSD_PTRDIFF_T_)
  58. #define _PTRDIFF_T
  59. #endif
  60. /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
  61. instead of _WCHAR_T_. */
  62. #if !defined(_WCHAR_T_) && !defined(_BSD_WCHAR_T_)
  63. #ifndef _BSD_WCHAR_T_
  64. #define _WCHAR_T
  65. #endif
  66. #endif
  67. /* Undef _FOO_T_ if we are supposed to define foo_t. */
  68. #if defined (__need_ptrdiff_t) || defined (_STDDEF_H_)
  69. #undef _PTRDIFF_T_
  70. #undef _BSD_PTRDIFF_T_
  71. #endif
  72. #if defined (__need_size_t) || defined (_STDDEF_H_)
  73. #undef _SIZE_T_
  74. #undef _BSD_SIZE_T_
  75. #endif
  76. #if defined (__need_wchar_t) || defined (_STDDEF_H_)
  77. #undef _WCHAR_T_
  78. #undef _BSD_WCHAR_T_
  79. #endif
  80. #endif /* defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) */
  81. /* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
  82. Just ignore it. */
  83. #if defined (__sequent__) && defined (_PTRDIFF_T_)
  84. #undef _PTRDIFF_T_
  85. #endif
  86. /* On VxWorks, <type/vxTypesBase.h> may have defined macros like
  87. _TYPE_size_t which will typedef size_t. fixincludes patched the
  88. vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
  89. not defined, and so that defining this macro defines _GCC_SIZE_T.
  90. If we find that the macros are still defined at this point, we must
  91. invoke them so that the type is defined as expected. */
  92. #if defined (_TYPE_ptrdiff_t) && (defined (__need_ptrdiff_t) || defined (_STDDEF_H_))
  93. _TYPE_ptrdiff_t;
  94. #undef _TYPE_ptrdiff_t
  95. #endif
  96. #if defined (_TYPE_size_t) && (defined (__need_size_t) || defined (_STDDEF_H_))
  97. _TYPE_size_t;
  98. #undef _TYPE_size_t
  99. #endif
  100. #if defined (_TYPE_wchar_t) && (defined (__need_wchar_t) || defined (_STDDEF_H_))
  101. _TYPE_wchar_t;
  102. #undef _TYPE_wchar_t
  103. #endif
  104. /* In case nobody has defined these types, but we aren't running under
  105. GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and
  106. __WCHAR_TYPE__ have reasonable values. This can happen if the
  107. parts of GCC is compiled by an older compiler, that actually
  108. include gstddef.h, such as collect2. */
  109. /* Signed type of difference of two pointers. */
  110. /* Define this type if we are doing the whole job,
  111. or if we want this type in particular. */
  112. #if defined (_STDDEF_H) || defined (__need_ptrdiff_t)
  113. #ifndef _PTRDIFF_T /* in case <sys/types.h> has defined it. */
  114. #ifndef _T_PTRDIFF_
  115. #ifndef _T_PTRDIFF
  116. #ifndef __PTRDIFF_T
  117. #ifndef _PTRDIFF_T_
  118. #ifndef _BSD_PTRDIFF_T_
  119. #ifndef ___int_ptrdiff_t_h
  120. #ifndef _GCC_PTRDIFF_T
  121. #ifndef _PTRDIFF_T_DECLARED /* DragonFly */
  122. #define _PTRDIFF_T
  123. #define _T_PTRDIFF_
  124. #define _T_PTRDIFF
  125. #define __PTRDIFF_T
  126. #define _PTRDIFF_T_
  127. #define _BSD_PTRDIFF_T_
  128. #define ___int_ptrdiff_t_h
  129. #define _GCC_PTRDIFF_T
  130. #define _PTRDIFF_T_DECLARED
  131. #ifndef __PTRDIFF_TYPE__
  132. #define __PTRDIFF_TYPE__ long int
  133. #endif
  134. typedef __PTRDIFF_TYPE__ ptrdiff_t;
  135. #endif /* _PTRDIFF_T_DECLARED */
  136. #endif /* _GCC_PTRDIFF_T */
  137. #endif /* ___int_ptrdiff_t_h */
  138. #endif /* _BSD_PTRDIFF_T_ */
  139. #endif /* _PTRDIFF_T_ */
  140. #endif /* __PTRDIFF_T */
  141. #endif /* _T_PTRDIFF */
  142. #endif /* _T_PTRDIFF_ */
  143. #endif /* _PTRDIFF_T */
  144. /* If this symbol has done its job, get rid of it. */
  145. #undef __need_ptrdiff_t
  146. #endif /* _STDDEF_H or __need_ptrdiff_t. */
  147. /* Unsigned type of `sizeof' something. */
  148. /* Define this type if we are doing the whole job,
  149. or if we want this type in particular. */
  150. #if defined (_STDDEF_H) || defined (__need_size_t)
  151. #ifndef __size_t__ /* BeOS */
  152. #ifndef __SIZE_T__ /* Cray Unicos/Mk */
  153. #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
  154. #ifndef _SYS_SIZE_T_H
  155. #ifndef _T_SIZE_
  156. #ifndef _T_SIZE
  157. #ifndef __SIZE_T
  158. #ifndef _SIZE_T_
  159. #ifndef _BSD_SIZE_T_
  160. #ifndef _SIZE_T_DEFINED_
  161. #ifndef _SIZE_T_DEFINED
  162. #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
  163. #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
  164. #ifndef ___int_size_t_h
  165. #ifndef _GCC_SIZE_T
  166. #ifndef _SIZET_
  167. #ifndef __size_t
  168. #define __size_t__ /* BeOS */
  169. #define __SIZE_T__ /* Cray Unicos/Mk */
  170. #define _SIZE_T
  171. #define _SYS_SIZE_T_H
  172. #define _T_SIZE_
  173. #define _T_SIZE
  174. #define __SIZE_T
  175. #define _SIZE_T_
  176. #define _BSD_SIZE_T_
  177. #define _SIZE_T_DEFINED_
  178. #define _SIZE_T_DEFINED
  179. #define _BSD_SIZE_T_DEFINED_ /* Darwin */
  180. #define _SIZE_T_DECLARED /* FreeBSD 5 */
  181. #define ___int_size_t_h
  182. #define _GCC_SIZE_T
  183. #define _SIZET_
  184. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
  185. || defined(__DragonFly__) \
  186. || defined(__FreeBSD_kernel__)
  187. /* __size_t is a typedef on FreeBSD 5, must not trash it. */
  188. #elif defined (__VMS__)
  189. /* __size_t is also a typedef on VMS. */
  190. #else
  191. #define __size_t
  192. #endif
  193. #ifndef __SIZE_TYPE__
  194. #define __SIZE_TYPE__ long unsigned int
  195. #endif
  196. #if !(defined (__GNUG__) && defined (size_t))
  197. typedef __SIZE_TYPE__ size_t;
  198. #ifdef __BEOS__
  199. typedef long ssize_t;
  200. #endif /* __BEOS__ */
  201. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  202. #endif /* __size_t */
  203. #endif /* _SIZET_ */
  204. #endif /* _GCC_SIZE_T */
  205. #endif /* ___int_size_t_h */
  206. #endif /* _SIZE_T_DECLARED */
  207. #endif /* _BSD_SIZE_T_DEFINED_ */
  208. #endif /* _SIZE_T_DEFINED */
  209. #endif /* _SIZE_T_DEFINED_ */
  210. #endif /* _BSD_SIZE_T_ */
  211. #endif /* _SIZE_T_ */
  212. #endif /* __SIZE_T */
  213. #endif /* _T_SIZE */
  214. #endif /* _T_SIZE_ */
  215. #endif /* _SYS_SIZE_T_H */
  216. #endif /* _SIZE_T */
  217. #endif /* __SIZE_T__ */
  218. #endif /* __size_t__ */
  219. #undef __need_size_t
  220. #endif /* _STDDEF_H or __need_size_t. */
  221. /* Wide character type.
  222. Locale-writers should change this as necessary to
  223. be big enough to hold unique values not between 0 and 127,
  224. and not (wchar_t) -1, for each defined multibyte character. */
  225. /* Define this type if we are doing the whole job,
  226. or if we want this type in particular. */
  227. #if defined (_STDDEF_H) || defined (__need_wchar_t)
  228. #ifndef __wchar_t__ /* BeOS */
  229. #ifndef __WCHAR_T__ /* Cray Unicos/Mk */
  230. #ifndef _WCHAR_T
  231. #ifndef _T_WCHAR_
  232. #ifndef _T_WCHAR
  233. #ifndef __WCHAR_T
  234. #ifndef _WCHAR_T_
  235. #ifndef _BSD_WCHAR_T_
  236. #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */
  237. #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */
  238. #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */
  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. /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
  261. instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other
  262. symbols in the _FOO_T_ family, stays defined even after its
  263. corresponding type is defined). If we define wchar_t, then we
  264. must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if
  265. we undef _WCHAR_T_, then we must also define rune_t, since
  266. headers like runetype.h assume that if machine/ansi.h is included,
  267. and _BSD_WCHAR_T_ is not defined, then rune_t is available.
  268. machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of
  269. the same type." */
  270. #ifdef _BSD_WCHAR_T_
  271. #undef _BSD_WCHAR_T_
  272. #ifdef _BSD_RUNE_T_
  273. #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
  274. typedef _BSD_RUNE_T_ rune_t;
  275. #define _BSD_WCHAR_T_DEFINED_
  276. #define _BSD_RUNE_T_DEFINED_ /* Darwin */
  277. #if defined (__FreeBSD__) && (__FreeBSD__ < 5)
  278. /* Why is this file so hard to maintain properly? In contrast to
  279. the comment above regarding BSD/386 1.1, on FreeBSD for as long
  280. as the symbol has existed, _BSD_RUNE_T_ must not stay defined or
  281. redundant typedefs will occur when stdlib.h is included after this file. */
  282. #undef _BSD_RUNE_T_
  283. #endif
  284. #endif
  285. #endif
  286. #endif
  287. /* FreeBSD 5 can't be handled well using "traditional" logic above
  288. since it no longer defines _BSD_RUNE_T_ yet still desires to export
  289. rune_t in some cases... */
  290. #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
  291. #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
  292. #if __BSD_VISIBLE
  293. #ifndef _RUNE_T_DECLARED
  294. typedef __rune_t rune_t;
  295. #define _RUNE_T_DECLARED
  296. #endif
  297. #endif
  298. #endif
  299. #endif
  300. #ifndef __WCHAR_TYPE__
  301. #define __WCHAR_TYPE__ int
  302. #endif
  303. #ifndef __cplusplus
  304. typedef __WCHAR_TYPE__ wchar_t;
  305. #endif
  306. #endif
  307. #endif
  308. #endif
  309. #endif
  310. #endif
  311. #endif
  312. #endif /* _WCHAR_T_DECLARED */
  313. #endif /* _BSD_RUNE_T_DEFINED_ */
  314. #endif
  315. #endif
  316. #endif
  317. #endif
  318. #endif
  319. #endif
  320. #endif
  321. #endif /* __WCHAR_T__ */
  322. #endif /* __wchar_t__ */
  323. #undef __need_wchar_t
  324. #endif /* _STDDEF_H or __need_wchar_t. */
  325. #if defined (__need_wint_t)
  326. #ifndef _WINT_T
  327. #define _WINT_T
  328. #ifndef __WINT_TYPE__
  329. #define __WINT_TYPE__ unsigned int
  330. #endif
  331. typedef __WINT_TYPE__ wint_t;
  332. #endif
  333. #undef __need_wint_t
  334. #endif
  335. /* In 4.3bsd-net2, leave these undefined to indicate that size_t, etc.
  336. are already defined. */
  337. /* BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here. */
  338. /* NetBSD 5 requires the I386_ANSI_H and X86_64_ANSI_H checks here. */
  339. #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_)
  340. /* The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
  341. are probably typos and should be removed before 2.8 is released. */
  342. #ifdef _GCC_PTRDIFF_T_
  343. #undef _PTRDIFF_T_
  344. #undef _BSD_PTRDIFF_T_
  345. #endif
  346. #ifdef _GCC_SIZE_T_
  347. #undef _SIZE_T_
  348. #undef _BSD_SIZE_T_
  349. #endif
  350. #ifdef _GCC_WCHAR_T_
  351. #undef _WCHAR_T_
  352. #undef _BSD_WCHAR_T_
  353. #endif
  354. /* The following ones are the real ones. */
  355. #ifdef _GCC_PTRDIFF_T
  356. #undef _PTRDIFF_T_
  357. #undef _BSD_PTRDIFF_T_
  358. #endif
  359. #ifdef _GCC_SIZE_T
  360. #undef _SIZE_T_
  361. #undef _BSD_SIZE_T_
  362. #endif
  363. #ifdef _GCC_WCHAR_T
  364. #undef _WCHAR_T_
  365. #undef _BSD_WCHAR_T_
  366. #endif
  367. #endif /* _ANSI_H_ || _MACHINE_ANSI_H_ || _X86_64_ANSI_H_ || _I386_ANSI_H_ */
  368. #endif /* __sys_stdtypes_h */
  369. /* A null pointer constant. */
  370. #if defined (_STDDEF_H) || defined (__need_NULL)
  371. #undef NULL /* in case <stdio.h> has defined it. */
  372. #ifdef __GNUG__
  373. #define NULL __null
  374. #else /* G++ */
  375. #ifndef __cplusplus
  376. #define NULL ((void *)0)
  377. #else /* C++ */
  378. #define NULL 0
  379. #endif /* C++ */
  380. #endif /* G++ */
  381. #endif /* NULL not defined and <stddef.h> or need NULL. */
  382. #undef __need_NULL
  383. #ifdef _STDDEF_H
  384. /* Offset of member MEMBER in a struct of type TYPE. */
  385. #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
  386. #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
  387. || (defined(__cplusplus) && __cplusplus >= 201103L)
  388. #ifndef _GCC_MAX_ALIGN_T
  389. #define _GCC_MAX_ALIGN_T
  390. /* Type whose alignment is supported in every context and is at least
  391. as great as that of any standard type not using alignment
  392. specifiers. */
  393. typedef struct {
  394. long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
  395. long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
  396. } max_align_t;
  397. #endif
  398. #endif /* C11 or C++11. */
  399. #if defined(__cplusplus) && __cplusplus >= 201103L
  400. #ifndef _GXX_NULLPTR_T
  401. #define _GXX_NULLPTR_T
  402. typedef decltype(nullptr) nullptr_t;
  403. #endif
  404. #endif /* C++11. */
  405. #endif /* _STDDEF_H was defined this time */
  406. #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__
  407. || __need_XXX was not defined before */