1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_CCOMPILE_H 28 #define _SYS_CCOMPILE_H 29 30 /* 31 * This file contains definitions designed to enable different compilers 32 * to be used harmoniously on Solaris systems. 33 */ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* 40 * Allow for version tests for compiler bugs and features. 41 */ 42 #if defined(__GNUC__) 43 #define __GNUC_VERSION \ 44 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 45 #else 46 #define __GNUC_VERSION 0 47 #endif 48 49 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__) 50 51 /* 52 * analogous to lint's PRINTFLIKEn 53 */ 54 #define __sun_attr___PRINTFLIKE__(__n) \ 55 __attribute__((__format__(printf, __n, (__n)+1))) 56 #define __sun_attr___VPRINTFLIKE__(__n) \ 57 __attribute__((__format__(printf, __n, 0))) 58 59 /* 60 * Handle the kernel printf routines that can take '%b' too 61 */ 62 #if __GNUC_VERSION < 30402 63 /* 64 * XX64 at least this doesn't work correctly yet with 3.4.1 anyway! 65 */ 66 #define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__ 67 #define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__ 68 #else 69 #define __sun_attr___KPRINTFLIKE__(__n) \ 70 __attribute__((__format__(cmn_err, __n, (__n)+1))) 71 #define __sun_attr___KVPRINTFLIKE__(__n) \ 72 __attribute__((__format__(cmn_err, __n, 0))) 73 #endif 74 75 /* 76 * This one's pretty obvious -- the function never returns 77 */ 78 #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 79 80 /* 81 * The function is 'extern inline' and expects GNU C89 behaviour, not C99 82 * behaviour. 83 * 84 * Should only be used on 'extern inline' definitions for GCC. 85 */ 86 #if __GNUC_VERSION >= 40300 87 #define __sun_attr___gnu_inline__ __attribute__((__gnu_inline__)) 88 #else 89 #define __sun_attr___gnu_inline__ 90 #endif 91 92 /* 93 * This is an appropriate label for functions that do not 94 * modify their arguments, e.g. strlen() 95 */ 96 #define __sun_attr___pure__ __attribute__((__pure__)) 97 98 /* 99 * This is a stronger form of __pure__. Can be used for functions 100 * that do not modify their arguments and don't depend on global 101 * memory. 102 */ 103 #define __sun_attr___const__ __attribute__((__const__)) 104 105 /* 106 * structure packing like #pragma pack(1) 107 */ 108 #define __sun_attr___packed__ __attribute__((__packed__)) 109 110 #define ___sun_attr_inner(__a) __sun_attr_##__a 111 #define __sun_attr__(__a) ___sun_attr_inner __a 112 113 #else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 114 115 #define __sun_attr__(__a) 116 117 #endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 118 119 /* 120 * Shorthand versions for readability 121 */ 122 123 #define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n))) 124 #define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n))) 125 #define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n))) 126 #define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n))) 127 #define __NORETURN __sun_attr__((__noreturn__)) 128 #define __GNU_INLINE __inline__ __sun_attr__((__gnu_inline__)) 129 #define __CONST __sun_attr__((__const__)) 130 #define __PURE __sun_attr__((__pure__)) 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* _SYS_CCOMPILE_H */ 137