stddef.h revision e25d3df6df39ecca4dad4647be2713cb85653634
18ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman/*===---- stddef.h - Basic type definitions --------------------------------===
28ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *
38ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * Copyright (c) 2008 Eli Friedman
48ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *
58ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * Permission is hereby granted, free of charge, to any person obtaining a copy
68ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * of this software and associated documentation files (the "Software"), to deal
78ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * in the Software without restriction, including without limitation the rights
88ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
98ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * copies of the Software, and to permit persons to whom the Software is
108ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * furnished to do so, subject to the following conditions:
118ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *
128ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * The above copyright notice and this permission notice shall be included in
138ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * all copies or substantial portions of the Software.
148ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *
158ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
188ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
208ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
218ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman * THE SOFTWARE.
228ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *
238ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman *===-----------------------------------------------------------------------===
248ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman */
258ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman
268ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#ifndef __STDDEF_H
278ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#define __STDDEF_H
288ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman
298da6bca896546cd98ad6aefaa3e9eba77736ea7bTed Kremenek#ifndef _PTRDIFF_T
308da6bca896546cd98ad6aefaa3e9eba77736ea7bTed Kremenek#define _PTRDIFF_T
318ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedmantypedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t;
328da6bca896546cd98ad6aefaa3e9eba77736ea7bTed Kremenek#endif
3321259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#ifndef _SIZE_T
3421259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#define _SIZE_T
358ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedmantypedef __typeof__(sizeof(int)) size_t;
3621259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#endif
378ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#ifndef __cplusplus
3821259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#ifndef _WCHAR_T
3921259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#define _WCHAR_T
406d6370ee10ddcd8cacc44c2d6796800c1325c732Chris Lattnertypedef __WCHAR_TYPE__ wchar_t;
418ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#endif
4221259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#endif
438ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman
4421259bafdc0e113c8bdce51d7911cc9880da1892Ted Kremenek#undef NULL
45f8e61b371d085516b8b9b906099db3e0b915a7c0Anders Carlsson#ifdef __cplusplus
4608e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#  if !defined(__MINGW32__) && !defined(_MSC_VER)
4708e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#    define NULL __null
4808e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#  else
4908e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#    define NULL 0
5008e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#  endif
51f8e61b371d085516b8b9b906099db3e0b915a7c0Anders Carlsson#else
5208e46f97ec8c00cc1bfe87fcd014db211a878ffbNico Weber#  define NULL ((void*)0)
53f8e61b371d085516b8b9b906099db3e0b915a7c0Anders Carlsson#endif
54f8e61b371d085516b8b9b906099db3e0b915a7c0Anders Carlsson
55e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregor#ifdef __cplusplus
56e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregor#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
57e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregornamespace std { typedef decltype(nullptr) nullptr_t; }
58e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregorusing ::std::nullptr_t;
59e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregor#endif
60e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregor#endif
61e25d3df6df39ecca4dad4647be2713cb85653634Douglas Gregor
628ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#define offsetof(t, d) __builtin_offsetof(t, d)
638ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman
648ba179d4a39c79ae486472a5f413f763ffcc0739Eli Friedman#endif /* __STDDEF_H */
6551f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi
6651f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
67fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
6851f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#if defined(__need_wint_t)
6951f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#if !defined(_WINT_T)
7051f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#define _WINT_T
7151f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumitypedef __WINT_TYPE__ wint_t;
7251f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#endif /* _WINT_T */
7351f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#undef __need_wint_t
7451f56fc36e6d441b6dd722cc09c4ac9f081c0974NAKAMURA Takumi#endif /* __need_wint_t */
75