cdefs.h revision 1.136
1/* $NetBSD: cdefs.h,v 1.136 2018/08/12 10:43:04 skrll Exp $ */ 2 3/* * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Berkeley Software Design, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 34 */ 35 36#ifndef _SYS_CDEFS_H_ 37#define _SYS_CDEFS_H_ 38 39#ifdef _KERNEL_OPT 40#include "opt_diagnostic.h" 41#endif 42 43/* 44 * Macro to test if we're using a GNU C compiler of a specific vintage 45 * or later, for e.g. features that appeared in a particular version 46 * of GNU C. Usage: 47 * 48 * #if __GNUC_PREREQ__(major, minor) 49 * ...cool feature... 50 * #else 51 * ...delete feature... 52 * #endif 53 */ 54#ifdef __GNUC__ 55#define __GNUC_PREREQ__(x, y) \ 56 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 57 (__GNUC__ > (x))) 58#else 59#define __GNUC_PREREQ__(x, y) 0 60#endif 61 62#include <machine/cdefs.h> 63#ifdef __ELF__ 64#include <sys/cdefs_elf.h> 65#else 66#include <sys/cdefs_aout.h> 67#endif 68 69#ifdef __GNUC__ 70#define __strict_weak_alias(alias,sym) \ 71 __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ 72 __weak_alias(alias,sym) 73#else 74#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) 75#endif 76 77/* 78 * Optional marker for size-optimised MD calling convention. 79 */ 80#ifndef __compactcall 81#define __compactcall 82#endif 83 84/* 85 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 86 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 87 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 88 * in between its arguments. __CONCAT can also concatenate double-quoted 89 * strings produced by the __STRING macro, but this only works with ANSI C. 90 */ 91 92#define ___STRING(x) __STRING(x) 93#define ___CONCAT(x,y) __CONCAT(x,y) 94 95#if __STDC__ || defined(__cplusplus) 96#define __P(protos) protos /* full-blown ANSI C */ 97#define __CONCAT(x,y) x ## y 98#define __STRING(x) #x 99 100#define __const const /* define reserved names to standard */ 101#define __signed signed 102#define __volatile volatile 103#if defined(__cplusplus) || defined(__PCC__) 104#define __inline inline /* convert to C++/C99 keyword */ 105#else 106#if !defined(__GNUC__) && !defined(__lint__) 107#define __inline /* delete GCC keyword */ 108#endif /* !__GNUC__ && !__lint__ */ 109#endif /* !__cplusplus */ 110 111#else /* !(__STDC__ || __cplusplus) */ 112#define __P(protos) () /* traditional C preprocessor */ 113#define __CONCAT(x,y) x/**/y 114#define __STRING(x) "x" 115 116#ifndef __GNUC__ 117#define __const /* delete pseudo-ANSI C keywords */ 118#define __inline 119#define __signed 120#define __volatile 121#endif /* !__GNUC__ */ 122 123/* 124 * In non-ANSI C environments, new programs will want ANSI-only C keywords 125 * deleted from the program and old programs will want them left alone. 126 * Programs using the ANSI C keywords const, inline etc. as normal 127 * identifiers should define -DNO_ANSI_KEYWORDS. 128 */ 129#ifndef NO_ANSI_KEYWORDS 130#define const __const /* convert ANSI C keywords */ 131#define inline __inline 132#define signed __signed 133#define volatile __volatile 134#endif /* !NO_ANSI_KEYWORDS */ 135#endif /* !(__STDC__ || __cplusplus) */ 136 137/* 138 * Used for internal auditing of the NetBSD source tree. 139 */ 140#ifdef __AUDIT__ 141#define __aconst __const 142#else 143#define __aconst 144#endif 145 146/* 147 * Compile Time Assertion. 148 */ 149#ifdef __COUNTER__ 150#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) 151#else 152#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) 153#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ 154 __CONCAT(_,b)) 155#endif 156#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) 157#define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused 158 159/* 160 * The following macro is used to remove const cast-away warnings 161 * from gcc -Wcast-qual; it should be used with caution because it 162 * can hide valid errors; in particular most valid uses are in 163 * situations where the API requires it, not to cast away string 164 * constants. We don't use *intptr_t on purpose here and we are 165 * explicit about unsigned long so that we don't have additional 166 * dependencies. 167 */ 168#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 169 170/* 171 * The following macro is used to remove the volatile cast-away warnings 172 * from gcc -Wcast-qual; as above it should be used with caution 173 * because it can hide valid errors or warnings. Valid uses include 174 * making it possible to pass a volatile pointer to memset(). 175 * For the same reasons as above, we use unsigned long and not intptr_t. 176 */ 177#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) 178 179/* 180 * GCC2 provides __extension__ to suppress warnings for various GNU C 181 * language extensions under "-ansi -pedantic". 182 */ 183#if !__GNUC_PREREQ__(2, 0) 184#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 185#endif 186 187/* 188 * GCC1 and some versions of GCC2 declare dead (non-returning) and 189 * pure (no side effects) functions using "volatile" and "const"; 190 * unfortunately, these then cause warnings under "-ansi -pedantic". 191 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 192 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 193 * in the distribution version of 2.5.5). 194 * 195 * GCC defines a pure function as depending only on its arguments and 196 * global variables. Typical examples are strlen and sqrt. 197 * 198 * GCC defines a const function as depending only on its arguments. 199 * Therefore calling a const function again with identical arguments 200 * will always produce the same result. 201 * 202 * Rounding modes for floating point operations are considered global 203 * variables and prevent sqrt from being a const function. 204 * 205 * Calls to const functions can be optimised away and moved around 206 * without limitations. 207 */ 208#if !__GNUC_PREREQ__(2, 0) && !defined(__lint__) 209#define __attribute__(x) 210#endif 211 212#if __GNUC_PREREQ__(2, 5) 213#define __dead __attribute__((__noreturn__)) 214#elif defined(__GNUC__) 215#define __dead __volatile 216#else 217#define __dead 218#endif 219 220#if __GNUC_PREREQ__(2, 96) 221#define __pure __attribute__((__pure__)) 222#elif defined(__GNUC__) 223#define __pure __const 224#else 225#define __pure 226#endif 227 228#if __GNUC_PREREQ__(2, 5) 229#define __constfunc __attribute__((__const__)) 230#else 231#define __constfunc 232#endif 233 234#if __GNUC_PREREQ__(3, 0) 235#define __noinline __attribute__((__noinline__)) 236#else 237#define __noinline /* nothing */ 238#endif 239 240#if __GNUC_PREREQ__(3, 0) 241#define __always_inline __attribute__((__always_inline__)) 242#else 243#define __always_inline /* nothing */ 244#endif 245 246#if __GNUC_PREREQ__(4, 1) 247#define __returns_twice __attribute__((__returns_twice__)) 248#else 249#define __returns_twice /* nothing */ 250#endif 251 252#if __GNUC_PREREQ__(4, 5) 253#define __noclone __attribute__((__noclone__)) 254#else 255#define __noclone /* nothing */ 256#endif 257 258/* 259 * __unused: Note that item or function might be unused. 260 */ 261#if __GNUC_PREREQ__(2, 7) || defined(__lint__) 262#define __unused __attribute__((__unused__)) 263#else 264#define __unused /* delete */ 265#endif 266 267/* 268 * __used: Note that item is needed, even if it appears to be unused. 269 */ 270#if __GNUC_PREREQ__(3, 1) 271#define __used __attribute__((__used__)) 272#else 273#define __used __unused 274#endif 275 276/* 277 * __diagused: Note that item is used in diagnostic code, but may be 278 * unused in non-diagnostic code. 279 */ 280#if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ 281 || (!defined(_KERNEL) && !defined(NDEBUG)) 282#define __diagused /* empty */ 283#else 284#define __diagused __unused 285#endif 286 287/* 288 * __debugused: Note that item is used in debug code, but may be 289 * unused in non-debug code. 290 */ 291#if defined(DEBUG) 292#define __debugused /* empty */ 293#else 294#define __debugused __unused 295#endif 296 297#if __GNUC_PREREQ__(3, 1) 298#define __noprofile __attribute__((__no_instrument_function__)) 299#else 300#define __noprofile /* nothing */ 301#endif 302 303#if __GNUC_PREREQ__(4, 6) || defined(__clang__) 304#define __unreachable() __builtin_unreachable() 305#else 306#define __unreachable() do {} while (/*CONSTCOND*/0) 307#endif 308 309/* 310 * To be used when an empty body is required like: 311 * 312 * #ifdef DEBUG 313 * # define dprintf(a) printf(a) 314 * #else 315 * # define dprintf(a) __nothing 316 * #endif 317 * 318 * We use ((void)0) instead of do {} while (0) so that it 319 * works on , expressions. 320 */ 321#define __nothing ((void)0) 322 323#if defined(__cplusplus) 324#define __BEGIN_EXTERN_C extern "C" { 325#define __END_EXTERN_C } 326#define __static_cast(x,y) static_cast<x>(y) 327#else 328#define __BEGIN_EXTERN_C 329#define __END_EXTERN_C 330#define __static_cast(x,y) (x)y 331#endif 332 333#if __GNUC_PREREQ__(4, 0) 334# define __dso_public __attribute__((__visibility__("default"))) 335# define __dso_hidden __attribute__((__visibility__("hidden"))) 336# define __BEGIN_PUBLIC_DECLS \ 337 _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C 338# define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") 339# define __BEGIN_HIDDEN_DECLS \ 340 _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C 341# define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") 342#else 343# define __dso_public 344# define __dso_hidden 345# define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C 346# define __END_PUBLIC_DECLS __END_EXTERN_C 347# define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C 348# define __END_HIDDEN_DECLS __END_EXTERN_C 349#endif 350#if __GNUC_PREREQ__(4, 2) 351# define __dso_protected __attribute__((__visibility__("protected"))) 352#else 353# define __dso_protected 354#endif 355 356#define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS 357#define __END_DECLS __END_PUBLIC_DECLS 358 359/* 360 * Non-static C99 inline functions are optional bodies. They don't 361 * create global symbols if not used, but can be replaced if desirable. 362 * This differs from the behavior of GCC before version 4.3. The nearest 363 * equivalent for older GCC is `extern inline'. For newer GCC, use the 364 * gnu_inline attribute additionally to get the old behavior. 365 * 366 * For C99 compilers other than GCC, the C99 behavior is expected. 367 */ 368#if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) 369#define __c99inline extern __attribute__((__gnu_inline__)) __inline 370#elif defined(__GNUC__) 371#define __c99inline extern __inline 372#elif defined(__STDC_VERSION__) || defined(__lint__) 373#define __c99inline __inline 374#endif 375 376#if defined(__lint__) 377#define __thread /* delete */ 378#define __packed __packed 379#define __aligned(x) /* delete */ 380#define __section(x) /* delete */ 381#elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) 382#define __packed __attribute__((__packed__)) 383#define __aligned(x) __attribute__((__aligned__(x))) 384#define __section(x) __attribute__((__section__(x))) 385#elif defined(_MSC_VER) 386#define __packed /* ignore */ 387#else 388#define __packed error: no __packed for this compiler 389#define __aligned(x) error: no __aligned for this compiler 390#define __section(x) error: no __section for this compiler 391#endif 392 393/* 394 * C99 defines the restrict type qualifier keyword, which was made available 395 * in GCC 2.92. 396 */ 397#if defined(__lint__) 398#define __restrict /* delete __restrict when not supported */ 399#elif __STDC_VERSION__ >= 199901L 400#define __restrict restrict 401#elif __GNUC_PREREQ__(2, 92) 402#define __restrict __restrict__ 403#else 404#define __restrict /* delete __restrict when not supported */ 405#endif 406 407/* 408 * C99 defines __func__ predefined identifier, which was made available 409 * in GCC 2.95. 410 */ 411#if !(__STDC_VERSION__ >= 199901L) 412#if __GNUC_PREREQ__(2, 6) 413#define __func__ __PRETTY_FUNCTION__ 414#elif __GNUC_PREREQ__(2, 4) 415#define __func__ __FUNCTION__ 416#else 417#define __func__ "" 418#endif 419#endif /* !(__STDC_VERSION__ >= 199901L) */ 420 421#if defined(_KERNEL) 422#if defined(NO_KERNEL_RCSIDS) 423#undef __KERNEL_RCSID 424#define __KERNEL_RCSID(_n, _s) /* nothing */ 425#endif /* NO_KERNEL_RCSIDS */ 426#endif /* _KERNEL */ 427 428#if !defined(_STANDALONE) && !defined(_KERNEL) 429#if defined(__GNUC__) || defined(__PCC__) 430#define __RENAME(x) ___RENAME(x) 431#elif defined(__lint__) 432#define __RENAME(x) __symbolrename(x) 433#else 434#error "No function renaming possible" 435#endif /* __GNUC__ */ 436#else /* _STANDALONE || _KERNEL */ 437#define __RENAME(x) no renaming in kernel/standalone environment 438#endif 439 440/* 441 * A barrier to stop the optimizer from moving code or assume live 442 * register values. This is gcc specific, the version is more or less 443 * arbitrary, might work with older compilers. 444 */ 445#if __GNUC_PREREQ__(2, 95) 446#define __insn_barrier() __asm __volatile("":::"memory") 447#else 448#define __insn_barrier() /* */ 449#endif 450 451/* 452 * GNU C version 2.96 adds explicit branch prediction so that 453 * the CPU back-end can hint the processor and also so that 454 * code blocks can be reordered such that the predicted path 455 * sees a more linear flow, thus improving cache behavior, etc. 456 * 457 * The following two macros provide us with a way to use this 458 * compiler feature. Use __predict_true() if you expect the expression 459 * to evaluate to true, and __predict_false() if you expect the 460 * expression to evaluate to false. 461 * 462 * A few notes about usage: 463 * 464 * * Generally, __predict_false() error condition checks (unless 465 * you have some _strong_ reason to do otherwise, in which case 466 * document it), and/or __predict_true() `no-error' condition 467 * checks, assuming you want to optimize for the no-error case. 468 * 469 * * Other than that, if you don't know the likelihood of a test 470 * succeeding from empirical or other `hard' evidence, don't 471 * make predictions. 472 * 473 * * These are meant to be used in places that are run `a lot'. 474 * It is wasteful to make predictions in code that is run 475 * seldomly (e.g. at subsystem initialization time) as the 476 * basic block reordering that this affects can often generate 477 * larger code. 478 */ 479#if __GNUC_PREREQ__(2, 96) 480#define __predict_true(exp) __builtin_expect((exp) != 0, 1) 481#define __predict_false(exp) __builtin_expect((exp) != 0, 0) 482#else 483#define __predict_true(exp) (exp) 484#define __predict_false(exp) (exp) 485#endif 486 487/* 488 * Compiler-dependent macros to declare that functions take printf-like 489 * or scanf-like arguments. They are null except for versions of gcc 490 * that are known to support the features properly (old versions of gcc-2 491 * didn't permit keeping the keywords out of the application namespace). 492 */ 493#if __GNUC_PREREQ__(2, 7) 494#define __printflike(fmtarg, firstvararg) \ 495 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 496#ifndef __syslog_attribute__ 497#define __syslog__ __printf__ 498#endif 499#define __sysloglike(fmtarg, firstvararg) \ 500 __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) 501#define __scanflike(fmtarg, firstvararg) \ 502 __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 503#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) 504#else 505#define __printflike(fmtarg, firstvararg) /* nothing */ 506#define __scanflike(fmtarg, firstvararg) /* nothing */ 507#define __sysloglike(fmtarg, firstvararg) /* nothing */ 508#define __format_arg(fmtarg) /* nothing */ 509#endif 510 511/* 512 * Macros for manipulating "link sets". Link sets are arrays of pointers 513 * to objects, which are gathered up by the linker. 514 * 515 * Object format-specific code has provided us with the following macros: 516 * 517 * __link_set_add_text(set, sym) 518 * Add a reference to the .text symbol `sym' to `set'. 519 * 520 * __link_set_add_rodata(set, sym) 521 * Add a reference to the .rodata symbol `sym' to `set'. 522 * 523 * __link_set_add_data(set, sym) 524 * Add a reference to the .data symbol `sym' to `set'. 525 * 526 * __link_set_add_bss(set, sym) 527 * Add a reference to the .bss symbol `sym' to `set'. 528 * 529 * __link_set_decl(set, ptype) 530 * Provide an extern declaration of the set `set', which 531 * contains an array of pointers to type `ptype'. This 532 * macro must be used by any code which wishes to reference 533 * the elements of a link set. 534 * 535 * __link_set_start(set) 536 * This points to the first slot in the link set. 537 * 538 * __link_set_end(set) 539 * This points to the (non-existent) slot after the last 540 * entry in the link set. 541 * 542 * __link_set_count(set) 543 * Count the number of entries in link set `set'. 544 * 545 * In addition, we provide the following macros for accessing link sets: 546 * 547 * __link_set_foreach(pvar, set) 548 * Iterate over the link set `set'. Because a link set is 549 * an array of pointers, pvar must be declared as "type **pvar", 550 * and the actual entry accessed as "*pvar". 551 * 552 * __link_set_entry(set, idx) 553 * Access the link set entry at index `idx' from set `set'. 554 */ 555#define __link_set_foreach(pvar, set) \ 556 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 557 558#define __link_set_entry(set, idx) (__link_set_start(set)[idx]) 559 560/* 561 * Return the natural alignment in bytes for the given type 562 */ 563#if __GNUC_PREREQ__(4, 1) 564#define __alignof(__t) __alignof__(__t) 565#else 566#define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) 567#endif 568 569/* 570 * Return the number of elements in a statically-allocated array, 571 * __x. 572 */ 573#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) 574 575#ifndef __ASSEMBLER__ 576/* __BIT(n): nth bit, where __BIT(0) == 0x1. */ 577#define __BIT(__n) \ 578 (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ 579 ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) 580 581/* Macros for min/max. */ 582#define __MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) 583#define __MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) 584 585/* __BITS(m, n): bits m through n, m < n. */ 586#define __BITS(__m, __n) \ 587 ((__BIT(__MAX((__m), (__n)) + 1) - 1) ^ (__BIT(__MIN((__m), (__n))) - 1)) 588#endif /* !__ASSEMBLER__ */ 589 590/* find least significant bit that is set */ 591#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) 592 593#define __PRIuBIT PRIuMAX 594#define __PRIuBITS __PRIuBIT 595 596#define __PRIxBIT PRIxMAX 597#define __PRIxBITS __PRIxBIT 598 599#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) 600#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) 601#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) 602 603/* 604 * Only to be used in other headers that are included from both c or c++ 605 * NOT to be used in code. 606 */ 607#ifdef __cplusplus 608#define __CAST(__dt, __st) static_cast<__dt>(__st) 609#else 610#define __CAST(__dt, __st) ((__dt)(__st)) 611#endif 612 613#define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) 614#define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) 615 616#define __USE(a) (/*LINTED*/(void)(a)) 617 618#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ 619 (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) 620 621#ifndef __ASSEMBLER__ 622static __inline long long __zeroll(void) { return 0; } 623static __inline unsigned long long __zeroull(void) { return 0; } 624#else 625#define __zeroll() (0LL) 626#define __zeroull() (0ULL) 627#endif 628 629#define __negative_p(x) (!((x) > 0) && ((x) != 0)) 630 631#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) 632#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) 633#define __type_min_u(t) ((t)0ULL) 634#define __type_max_u(t) ((t)~0ULL) 635#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) 636#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) 637#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) 638 639 640#define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ 641 (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) 642 643#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ 644 ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ 645 ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ 646 (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) 647 648/* 649 * return true if value 'a' fits in type 't' 650 */ 651#define __type_fit(t, a) (__type_is_signed(t) ? \ 652 __type_fit_s(t, a) : __type_fit_u(t, a)) 653 654#endif /* !_SYS_CDEFS_H_ */ 655