| 1 | // ==================================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : attributes.h // |
|---|
| 4 | // Purpose : declare attribute macros // |
|---|
| 5 | // // |
|---|
| 6 | // // |
|---|
| 7 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2005 // |
|---|
| 8 | // Copyright Department of Microbiology (Technical University Munich) // |
|---|
| 9 | // // |
|---|
| 10 | // Visit our web site at: http://www.arb-home.de/ // |
|---|
| 11 | // // |
|---|
| 12 | // ==================================================================== // |
|---|
| 13 | #ifndef ATTRIBUTES_H |
|---|
| 14 | #define ATTRIBUTES_H |
|---|
| 15 | |
|---|
| 16 | // ------------------------------------------------------------ |
|---|
| 17 | // short description of attributes defined: |
|---|
| 18 | // |
|---|
| 19 | // __ATTR__FORMAT(p) used for printf-like functions. 'p' is the position of the format string, args follow directly |
|---|
| 20 | // __ATTR__VFORMAT(p) used for vprintf-like functions. 'p' is the position of the format string, args are NOT checked |
|---|
| 21 | // __ATTR__SENTINEL used for function that expect a parameter list terminated by NULL |
|---|
| 22 | // __ATTR__NORETURN used for functions which do NEVER return |
|---|
| 23 | // __ATTR__DEPRECATED used for deprecated functions (useful for redesign) |
|---|
| 24 | // __ATTR__PURE used for functions w/o side-effects, where result only depends on parameters + global data |
|---|
| 25 | // __ATTR__CONST same as __ATTR__PURE, but w/o global-data-access |
|---|
| 26 | // __ATTR__USERESULT warn if result of function is unused |
|---|
| 27 | // |
|---|
| 28 | // __ATTR__FORMAT_MEMBER(p) same as __ATTR__FORMAT for member functions |
|---|
| 29 | // __ATTR__VFORMAT_MEMBER(p) same as __ATTR__VFORMAT for member functions |
|---|
| 30 | // |
|---|
| 31 | // ------------------------------------------------------------ |
|---|
| 32 | |
|---|
| 33 | #ifndef __GNUC__ |
|---|
| 34 | # error You have to use the gnu compiler! |
|---|
| 35 | #endif |
|---|
| 36 | #if (__GNUC__ < 3) |
|---|
| 37 | # error You have to use gcc 3.xx or above |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | #if (__GNUC__ >= 4) // gcc 4.x and above |
|---|
| 41 | # define __ATTR__SENTINEL __attribute__((sentinel)) |
|---|
| 42 | # define HAS_FUNCTION_TYPE_ATTRIBUTES |
|---|
| 43 | # if (__GNUC_MINOR__ >= 2) |
|---|
| 44 | # define __ATTR__USERESULT __attribute__((warn_unused_result)) |
|---|
| 45 | # endif |
|---|
| 46 | #endif |
|---|
| 47 | |
|---|
| 48 | #if (__GNUC__ == 3) // gcc 3.x |
|---|
| 49 | # if (__GNUC_MINOR__ >= 4) |
|---|
| 50 | # define HAS_FUNCTION_TYPE_ATTRIBUTES |
|---|
| 51 | # endif |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | // ------------------------------------------------------------ |
|---|
| 55 | // helper macro to declare attributes for function-pointers |
|---|
| 56 | |
|---|
| 57 | #ifdef HAS_FUNCTION_TYPE_ATTRIBUTES |
|---|
| 58 | #define FUNCTION_TYPE_ATTR(x) x |
|---|
| 59 | #else |
|---|
| 60 | #define FUNCTION_TYPE_ATTR(x) |
|---|
| 61 | #endif |
|---|
| 62 | |
|---|
| 63 | // ------------------------------------------------------------ |
|---|
| 64 | // helper macro to declare attributed function prototype and |
|---|
| 65 | // start function definition in one line |
|---|
| 66 | #define ATTRIBUTED(attribute, proto) proto attribute; proto |
|---|
| 67 | |
|---|
| 68 | // ------------------------------------------------------------ |
|---|
| 69 | // now define undefined attributes empty : |
|---|
| 70 | |
|---|
| 71 | #ifndef __ATTR__SENTINEL |
|---|
| 72 | # define __ATTR__SENTINEL |
|---|
| 73 | #endif |
|---|
| 74 | #ifndef __ATTR__USERESULT |
|---|
| 75 | # define __ATTR__USERESULT |
|---|
| 76 | #endif |
|---|
| 77 | |
|---|
| 78 | // ------------------------------------------------------------ |
|---|
| 79 | // valid for any gcc above 3.xx |
|---|
| 80 | |
|---|
| 81 | #define __ATTR__PURE __attribute__((pure)) |
|---|
| 82 | #define __ATTR__DEPRECATED __attribute__((deprecated)) |
|---|
| 83 | #define __ATTR__CONST __attribute__((const)) |
|---|
| 84 | #define __ATTR__NORETURN __attribute__((noreturn)) |
|---|
| 85 | |
|---|
| 86 | #define __ATTR__FORMAT(pos) __attribute__((format(__printf__, pos, (pos)+1))) |
|---|
| 87 | #define __ATTR__VFORMAT(pos) __attribute__((format(__printf__, pos, 0))) |
|---|
| 88 | #define __ATTR__FORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, (pos)+2))) |
|---|
| 89 | #define __ATTR__VFORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, 0))) |
|---|
| 90 | // when used for member functions, start with pos+1 (pos = 1 seems to be the this-pointer!?) |
|---|
| 91 | // ------------------------------------------------------------ |
|---|
| 92 | // |
|---|
| 93 | // |
|---|
| 94 | |
|---|
| 95 | #else |
|---|
| 96 | #error attributes.h included twice |
|---|
| 97 | #endif // ATTRIBUTES_H |
|---|
| 98 | |
|---|