1 1.2 riastrad /* $NetBSD: stddef.h,v 1.2 2025/04/01 00:33:55 riastradh Exp $ */ 2 1.1 christos 3 1.1 christos /*- 4 1.1 christos * Copyright (c) 1990, 1993 5 1.1 christos * The Regents of the University of California. All rights reserved. 6 1.1 christos * 7 1.1 christos * Redistribution and use in source and binary forms, with or without 8 1.1 christos * modification, are permitted provided that the following conditions 9 1.1 christos * are met: 10 1.1 christos * 1. Redistributions of source code must retain the above copyright 11 1.1 christos * notice, this list of conditions and the following disclaimer. 12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 christos * notice, this list of conditions and the following disclaimer in the 14 1.1 christos * documentation and/or other materials provided with the distribution. 15 1.1 christos * 3. Neither the name of the University nor the names of its contributors 16 1.1 christos * may be used to endorse or promote products derived from this software 17 1.1 christos * without specific prior written permission. 18 1.1 christos * 19 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 christos * SUCH DAMAGE. 30 1.1 christos * 31 1.1 christos * @(#)stddef.h 8.1 (Berkeley) 6/2/93 32 1.1 christos */ 33 1.1 christos 34 1.2 riastrad /* 35 1.2 riastrad * C99, 7.17: Common definitions <stddef.h> 36 1.2 riastrad * C11, 7.19: Common definitoins <stddef.h> 37 1.2 riastrad * C23, 7.21: Common definitions <stddef.h> 38 1.2 riastrad */ 39 1.2 riastrad 40 1.1 christos #ifndef _SYS_STDDEF_H_ 41 1.1 christos #define _SYS_STDDEF_H_ 42 1.1 christos 43 1.2 riastrad /* 44 1.2 riastrad * C23 `2. The macro 45 1.2 riastrad * 46 1.2 riastrad * __STDC_VERSION_STDDEF_H__ 47 1.2 riastrad * 48 1.2 riastrad * is an integer constant expression with a value equivalent 49 1.2 riastrad * to 202311L.' 50 1.2 riastrad */ 51 1.2 riastrad #if defined(_NETBSD_SOURCE) || defined(_ISOC23_SOURCE) || \ 52 1.2 riastrad (__STDC_VERSION__ - 0) >= 202311L 53 1.2 riastrad #define __STDC_VERSION_STDDEF_H__ 202311L 54 1.2 riastrad #endif 55 1.2 riastrad 56 1.1 christos #include <sys/cdefs.h> 57 1.1 christos #include <sys/featuretest.h> 58 1.1 christos #include <machine/ansi.h> 59 1.1 christos 60 1.2 riastrad /* 61 1.2 riastrad * C23 `3. The types are 62 1.2 riastrad * 63 1.2 riastrad * ptrdiff_t 64 1.2 riastrad * 65 1.2 riastrad * which is the signed integer type of the result of 66 1.2 riastrad * subtracting two pointers; 67 1.2 riastrad * 68 1.2 riastrad * size_t 69 1.2 riastrad * 70 1.2 riastrad * which is the unsigned integer type of the result of the 71 1.2 riastrad * sizeof operator; 72 1.2 riastrad * 73 1.2 riastrad * max_align_t 74 1.2 riastrad * 75 1.2 riastrad * which is an object type whose alignment is the greatest 76 1.2 riastrad * fundamental alignment; 77 1.2 riastrad * 78 1.2 riastrad * wchar_t 79 1.2 riastrad * 80 1.2 riastrad * which is an integer type whose range of values can 81 1.2 riastrad * represent distinct codes for all members of the largest 82 1.2 riastrad * extended chracter set specified among the supported 83 1.2 riastrad * locales; [...] and 84 1.2 riastrad * 85 1.2 riastrad * nullptr_t 86 1.2 riastrad * 87 1.2 riastrad * which is the type of the nullptr predefined constant, see 88 1.2 riastrad * below.' 89 1.2 riastrad */ 90 1.1 christos #ifdef _BSD_PTRDIFF_T_ 91 1.1 christos typedef _BSD_PTRDIFF_T_ ptrdiff_t; 92 1.1 christos #undef _BSD_PTRDIFF_T_ 93 1.1 christos #endif 94 1.1 christos 95 1.1 christos #ifdef _BSD_SIZE_T_ 96 1.1 christos typedef _BSD_SIZE_T_ size_t; 97 1.1 christos #undef _BSD_SIZE_T_ 98 1.1 christos #endif 99 1.1 christos 100 1.2 riastrad #if (__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L 101 1.2 riastrad typedef union { 102 1.2 riastrad void *_v; 103 1.2 riastrad long double _ld; 104 1.2 riastrad long long int _ll; 105 1.2 riastrad } max_align_t; 106 1.2 riastrad #endif 107 1.2 riastrad 108 1.1 christos #if defined(_BSD_WCHAR_T_) && !defined(__cplusplus) 109 1.1 christos typedef _BSD_WCHAR_T_ wchar_t; 110 1.1 christos #undef _BSD_WCHAR_T_ 111 1.1 christos #endif 112 1.1 christos 113 1.2 riastrad #if (__STDC_VERSION__ - 0) >= 202311L 114 1.2 riastrad typedef typeof_unqual(nullptr) nullptr_t; 115 1.2 riastrad #endif 116 1.2 riastrad 117 1.2 riastrad /* 118 1.2 riastrad * C23 `4. The macros are 119 1.2 riastrad * 120 1.2 riastrad * NULL 121 1.2 riastrad * 122 1.2 riastrad * which expands to an implementation-defined null pointer 123 1.2 riastrad * constant; 124 1.2 riastrad * 125 1.2 riastrad * unreachable() 126 1.2 riastrad * 127 1.2 riastrad * which expands to a void expression that invokes undefined 128 1.2 riastrad * behavior if it is reached during execution; and 129 1.2 riastrad * 130 1.2 riastrad * offsetof(type, member-designator) 131 1.2 riastrad * 132 1.2 riastrad * which expands to an integer constant expression that has 133 1.2 riastrad * type size_t, the value of which is the offset in bytes, to 134 1.2 riastrad * the subobject (designated by member-designator), from the 135 1.2 riastrad * beginning of any object of type type.' 136 1.2 riastrad */ 137 1.2 riastrad 138 1.1 christos #include <sys/null.h> 139 1.1 christos 140 1.2 riastrad #if (__STDC_VERSION__ - 0) >= 202311L 141 1.2 riastrad #define unreachable() __unreachable() /* sys/cdefs.h */ 142 1.2 riastrad #endif 143 1.2 riastrad 144 1.1 christos #if __GNUC_PREREQ__(4, 0) 145 1.1 christos #define offsetof(type, member) __builtin_offsetof(type, member) 146 1.1 christos #elif !defined(__cplusplus) 147 1.1 christos #define offsetof(type, member) ((size_t)(unsigned long)(&((type *)0)->member)) 148 1.1 christos #else 149 1.1 christos #if !__GNUC_PREREQ__(3, 4) 150 1.1 christos #define __offsetof__(a) a 151 1.1 christos #endif 152 1.1 christos #define offsetof(type, member) __offsetof__((reinterpret_cast<size_t> \ 153 1.1 christos (&reinterpret_cast<const volatile char &>(static_cast<type *>(0)->member)))) 154 1.1 christos #endif 155 1.1 christos 156 1.1 christos #endif /* _SYS_STDDEF_H_ */ 157