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