1 /* HTAB = 4 */ 2 /**************************************************************************** 3 * compiler.h -- Macro definitions used to handle compilers idiosyncrasies. * 4 *--------------------------------------------------------------------------* 5 * (c) 2002 Bertrand Petit * 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 * * 11 * 1. Redistributions of source code must retain the above copyright * 12 * notice, this list of conditions and the following disclaimer. * 13 * * 14 * 2. Redistributions in binary form must reproduce the above * 15 * copyright notice, this list of conditions and the following * 16 * disclaimer in the documentation and/or other materials provided * 17 * with the distribution. * 18 * * 19 * 3. Neither the name of the author nor the names of its contributors * 20 * may be used to endorse or promote products derived from this * 21 * software without specific prior written permission. * 22 * * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * 26 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR * 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * 30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * 31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 34 * SUCH DAMAGE. * 35 * * 36 ****************************************************************************/ 37 38 /* 39 * $Name$ 40 * $Date$ 41 * $Revision$ 42 */ 43 44 #ifndef COMPILER_H 45 #define COMPILER_H 46 47 /**************************************************************************** 48 * Macros. * 49 ****************************************************************************/ 50 51 /* Function attribute declaring that printf-like format string checks shall be 52 * performed on arguments at compile time. Format string and argument 53 * positions are 1-based. 54 * 55 * Declaration usage: 56 * _WITH_FORMAT_STRING(1, 2) FormatedLog(const char * Message, ...); 57 * 58 * Definition usage: 59 * _WITH_FORMAT_STRING(1, 2) FormatedLog(const char * Message, ...) {} 60 */ 61 #if defined(__GNUC__) || defined(__clang__) 62 # define _WITH_FORMAT_STRING(StringPos, ArgsPos) \ 63 __attribute__((__format__ (__printf__, StringPos, ArgsPos))) 64 #else /* __GNUC__ || __clang__ */ 65 # define _WITH_FORMAT_STRING(StringPos, ArgsPos) 66 #endif 67 68 /* Function attribute declaring that a function is an exit point. 69 * 70 * Declaration usage: 71 * _Noreturn void die(void) _NORETURN; 72 * 73 * Definition usage: 74 * _Noreturn void die(void) {} 75 */ 76 #if defined(__clang__) 77 # define _NORETURN 78 #elif defined(__GNUC__) 79 # define _Noreturn 80 # define _NORETURN __attribute__ ((noreturn)) 81 #else /* ! __GNUC__ and ! __clang__ */ 82 # define _Noreturn 83 # define _NORETURN 84 #endif 85 86 /* Variable attribute declaring that a variable is known to be unused. 87 * 88 * Usage in declarations: 89 * int foo(int bar _UNUSED_VARIABLE); // Optional 90 * extern const char *Name _UNUSED_VARIABLE; // Optional 91 * 92 * Usage in definitions: 93 * int foo(int bar _UNUSED_VARIABLE) {} 94 * const char *Name _UNUSED_VARIABLE = NULL; 95 */ 96 #if defined(__GNUC__) || defined(__clang__) 97 # define _UNUSED_VARIABLE __attribute__((__unused__)) 98 #else /* __GNUC__ || __clang__ */ 99 # define _UNUSED_VARIABLE 100 #endif 101 102 #endif /* COMPILER_H */ 103 104 /* 105 * Local Variables: 106 * tab-width: 4 107 * End: 108 */ 109 110 /**************************************************************************** 111 * End of file compiler.h * 112 ****************************************************************************/ 113