1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : attributes.h // |
---|
4 | // Purpose : declare attribute macros // |
---|
5 | // Time-stamp: <Mon Mar/03/2008 11:44 MET Coder@ReallySoft.de> // |
---|
6 | // // |
---|
7 | // // |
---|
8 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2005 // |
---|
9 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
10 | // // |
---|
11 | // Visit our web site at: http://www.arb-home.de/ // |
---|
12 | // // |
---|
13 | // ==================================================================== // |
---|
14 | #ifndef ATTRIBUTES_H |
---|
15 | #define ATTRIBUTES_H |
---|
16 | |
---|
17 | // ------------------------------------------------------------ |
---|
18 | // short description of attributes defined: |
---|
19 | // |
---|
20 | // __ATTR__FORMAT(p) used for printf-like functions. 'p' is the position of the format string, args follow directly |
---|
21 | // __ATTR__VFORMAT(p) used for vprintf-like functions. 'p' is the position of the format string, args are NOT checked |
---|
22 | // __ATTR__SENTINEL used for function that expect a parameter list terminated by NULL |
---|
23 | // __ATTR__NORETURN used for functions which do NEVER return |
---|
24 | // __ATTR__DEPRECATED used for deprecated functions (useful for redesign) |
---|
25 | // __ATTR__PURE used for functions w/o side-effects, where result only depends on parameters + global data |
---|
26 | // __ATTR__CONST same as __ATTR__PURE, but w/o global-data-access |
---|
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 | #endif |
---|
44 | |
---|
45 | #if (__GNUC__ == 3) // gcc 3.x |
---|
46 | #if (__GNUC_MINOR__ >= 4) |
---|
47 | #define HAS_FUNCTION_TYPE_ATTRIBUTES |
---|
48 | #endif |
---|
49 | #endif |
---|
50 | |
---|
51 | // ------------------------------------------------------------ |
---|
52 | // helper macro to declare attributes for function-pointers |
---|
53 | |
---|
54 | #ifdef HAS_FUNCTION_TYPE_ATTRIBUTES |
---|
55 | #define FUNCTION_TYPE_ATTR(x) x |
---|
56 | #else |
---|
57 | #define FUNCTION_TYPE_ATTR(x) |
---|
58 | #endif |
---|
59 | |
---|
60 | // ------------------------------------------------------------ |
---|
61 | // now define undefined attributes empty : |
---|
62 | |
---|
63 | #ifndef __ATTR__SENTINEL |
---|
64 | #define __ATTR__SENTINEL |
---|
65 | #endif |
---|
66 | |
---|
67 | // ------------------------------------------------------------ |
---|
68 | // valid for any gcc above 3.xx |
---|
69 | |
---|
70 | #define __ATTR__PURE __attribute__((pure)) |
---|
71 | #define __ATTR__DEPRECATED __attribute__((deprecated)) |
---|
72 | #define __ATTR__CONST __attribute__((const)) |
---|
73 | #define __ATTR__NORETURN __attribute__((noreturn)) |
---|
74 | |
---|
75 | #define __ATTR__FORMAT(pos) __attribute__((format(__printf__, pos, (pos)+1))) |
---|
76 | #define __ATTR__VFORMAT(pos) __attribute__((format(__printf__, pos, 0))) |
---|
77 | #define __ATTR__FORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, (pos)+2))) |
---|
78 | #define __ATTR__VFORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, 0))) |
---|
79 | // when used for member functions, start with pos+1 (pos = 1 seems to be the this-pointer!?) |
---|
80 | // ------------------------------------------------------------ |
---|
81 | |
---|
82 | #else |
---|
83 | #error attributes.h included twice |
---|
84 | #endif // ATTRIBUTES_H |
---|
85 | |
---|