cdefs.h revision 1.36
1/* $NetBSD: cdefs.h,v 1.36 2000/05/27 12:22:24 kleink Exp $ */ 2 3/* 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Berkeley Software Design, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 39 */ 40 41#ifndef _SYS_CDEFS_H_ 42#define _SYS_CDEFS_H_ 43 44/* 45 * Macro to test if we're using a GNU C compiler of a specific vintage 46 * or later, for e.g. features that appeared in a particular version 47 * of GNU C. Usage: 48 * 49 * #if __GNUC_PREREQ__(major, minor) 50 * ...cool feature... 51 * #else 52 * ...delete feature... 53 * #endif 54 */ 55#ifdef __GNUC__ 56#define __GNUC_PREREQ__(x, y) \ 57 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 58 (__GNUC__ > (x))) 59#else 60#define __GNUC_PREREQ__(x, y) 0 61#endif 62 63#include <machine/cdefs.h> 64#ifdef __ELF__ 65#include <sys/cdefs_elf.h> 66#else 67#include <sys/cdefs_aout.h> 68#endif 69 70#if defined(__cplusplus) 71#define __BEGIN_DECLS extern "C" { 72#define __END_DECLS }; 73#else 74#define __BEGIN_DECLS 75#define __END_DECLS 76#endif 77 78/* 79 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 80 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 81 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 82 * in between its arguments. __CONCAT can also concatenate double-quoted 83 * strings produced by the __STRING macro, but this only works with ANSI C. 84 */ 85 86#define ___STRING(x) __STRING(x) 87#define ___CONCAT(x,y) __CONCAT(x,y) 88 89#if defined(__STDC__) || defined(__cplusplus) 90#define __P(protos) protos /* full-blown ANSI C */ 91#define __CONCAT(x,y) x ## y 92#define __STRING(x) #x 93 94#define __const const /* define reserved names to standard */ 95#define __signed signed 96#define __volatile volatile 97#if defined(__cplusplus) 98#define __inline inline /* convert to C++ keyword */ 99#else 100#if !defined(__GNUC__) && !defined(__lint__) 101#define __inline /* delete GCC keyword */ 102#endif /* !__GNUC__ && !__lint__ */ 103#endif /* !__cplusplus */ 104 105#else /* !(__STDC__ || __cplusplus) */ 106#define __P(protos) () /* traditional C preprocessor */ 107#define __CONCAT(x,y) x/**/y 108#define __STRING(x) "x" 109 110#ifndef __GNUC__ 111#define __const /* delete pseudo-ANSI C keywords */ 112#define __inline 113#define __signed 114#define __volatile 115#endif /* !__GNUC__ */ 116 117/* 118 * In non-ANSI C environments, new programs will want ANSI-only C keywords 119 * deleted from the program and old programs will want them left alone. 120 * Programs using the ANSI C keywords const, inline etc. as normal 121 * identifiers should define -DNO_ANSI_KEYWORDS. 122 */ 123#ifndef NO_ANSI_KEYWORDS 124#define const __const /* convert ANSI C keywords */ 125#define inline __inline 126#define signed __signed 127#define volatile __volatile 128#endif /* !NO_ANSI_KEYWORDS */ 129#endif /* !(__STDC__ || __cplusplus) */ 130 131/* 132 * Used for internal auditing of the NetBSD source tree. 133 */ 134#ifdef __AUDIT__ 135#define __aconst __const 136#else 137#define __aconst 138#endif 139 140/* 141 * GCC2 provides __extension__ to suppress warnings for various GNU C 142 * language extensions under "-ansi -pedantic". 143 */ 144#if !__GNUC_PREREQ__(2, 0) 145#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 146#endif 147 148/* 149 * GCC1 and some versions of GCC2 declare dead (non-returning) and 150 * pure (no side effects) functions using "volatile" and "const"; 151 * unfortunately, these then cause warnings under "-ansi -pedantic". 152 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 153 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 154 * in the distribution version of 2.5.5). 155 */ 156#if !__GNUC_PREREQ__(2, 5) 157#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 158#if defined(__GNUC__) && !defined(__STRICT_ANSI__) 159#define __dead __volatile 160#define __pure __const 161#endif 162#endif 163 164#ifdef __KPRINTF_ATTRIBUTE__ 165#define __kprintf_attribute__(a) __attribute__(a) 166#else 167#define __kprintf_attribute__(a) 168#endif 169 170/* Delete pseudo-keywords wherever they are not available or needed. */ 171#ifndef __dead 172#define __dead 173#define __pure 174#endif 175 176#if defined(_KERNEL) 177#if defined(NO_KERNEL_RCSIDS) 178#undef __KERNEL_RCSID 179#define __KERNEL_RCSID(_n, _s) /* nothing */ 180#endif /* NO_KERNEL_RCSIDS */ 181#endif /* _KERNEL */ 182 183#if !defined(_STANDALONE) && !defined(_KERNEL) 184#ifdef __GNUC__ 185#define __RENAME(x) ___RENAME(x) 186#else 187#ifdef __lint__ 188#define __RENAME(x) __symbolrename(x) 189#else 190 #error "No function renaming possible" 191#endif /* __lint__ */ 192#endif /* __GNUC__ */ 193#else /* _STANDALONE || _KERNEL */ 194#define __RENAME(x) no renaming in kernel or standalone environment 195#endif 196 197/* 198 * GNU C version 2.96 adds explicit branch prediction so that 199 * the CPU back-end can hint the processor and also so that 200 * code blocks can be reordered such that the predicted path 201 * sees a more linear flow, thus improving cache behavior, etc. 202 * 203 * The following two macros provide us with a way to utilize this 204 * compiler feature. Use __predict_true() if you expect the expression 205 * to evaluate to true, and __predict_false() if you expect the 206 * expression to evaluate to false. 207 * 208 * A few notes about usage: 209 * 210 * * Generally, __predict_false() error condition checks (unless 211 * you have some _strong_ reason to do otherwise, in which case 212 * document it), and/or __predict_true() `no-error' condition 213 * checks, assuming you want to optimize for the no-error case. 214 * 215 * * Other than that, if you don't know the likelihood of a test 216 * succeeding from empirical or other `hard' evidence, don't 217 * make predictions. 218 * 219 * * These are meant to be used in places that are run `a lot'. 220 * It is wasteful to make predictions in code that is run 221 * seldomly (e.g. at subsystem initialization time) as the 222 * basic block reordering that this affects can often generate 223 * larger code. 224 */ 225#if __GNUC_PREREQ__(2, 96) 226#define __predict_true(exp) __builtin_expect(((exp) != 0), 1) 227#define __predict_false(exp) __builtin_expect(((exp) != 0), 0) 228#else 229#define __predict_true(exp) ((exp) != 0) 230#define __predict_false(exp) ((exp) != 0) 231#endif 232 233#endif /* !_SYS_CDEFS_H_ */ 234