From: Daniel Richard G Date: Mon, 6 Aug 2012 18:39:53 +0000 (+0200) Subject: Only define gcc function attributes on gcc. X-Git-Tag: v0.1.5~11^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=commitdiff_plain;h=e1f886f9d8e4386ecbca292ecb418440434a13e0;ds=sidebyside Only define gcc function attributes on gcc. These gcc extensions help the compiler optimize function calls, but are unavailable if dss is not compiled with gcc. This patch defines the corresponding macros to empty if __GNUC__ is not defined, or if the gcc version is too old to support the particular function attribute. --- diff --git a/gcc-compat.h b/gcc-compat.h index 4451980..a15b0ce 100644 --- a/gcc-compat.h +++ b/gcc-compat.h @@ -1,11 +1,35 @@ +#define HAVE_GNUC(maj, min) \ + defined(__GNUC__) && \ + (__GNUC__ > maj || (__GNUC__ == maj && __GNUC_MINOR__ >= min)) + +#if HAVE_GNUC(2,5) # define __noreturn __attribute__ ((noreturn)) +#else +# define __noreturn +#endif + +#if HAVE_GNUC(3,0) # define __malloc __attribute__ ((malloc)) +#else +# define __malloc +#endif + +#if HAVE_GNUC(2,7) # define __a_unused __attribute__ ((unused)) +#else +# define __a_unused +#endif + /* * p is the number of the "format string" parameter, and q is * the number of the first variadic parameter */ +#if HAVE_GNUC(2,3) # define __printf(p,q) __attribute__ ((format (printf, p, q))) +#else +# define __printf(p,q) +#endif + /* * as direct use of __printf(p,q) confuses doxygen, here are two extra macros * for those values p,q that are actually used by paraslash. @@ -13,10 +37,10 @@ #define __printf_1_2 __printf(1,2) #define __printf_2_3 __printf(2,3) -# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) +#if HAVE_GNUC(3,3) # define __must_check __attribute__ ((warn_unused_result)) -# else +#else # define __must_check /* no warn_unused_result */ -# endif +#endif #define _static_inline_ static inline