X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=compiler.h;h=a2689e8e46b770ee417a2a861d714140b3e20c8d;hb=18a2224fc3265deda8bc692a66bcbe489bc1837a;hp=0f6e8f7b423dcd81e79556e58005f53470ed077c;hpb=4dfb853d1935ae0ab4c5be187a82f832efc32fd8;p=bertos.git diff --git a/compiler.h b/compiler.h index 0f6e8f7b..a2689e8e 100755 --- a/compiler.h +++ b/compiler.h @@ -15,6 +15,9 @@ /* * $Log$ + * Revision 1.13 2004/08/02 20:20:29 aleph + * Merge from project_ks + * * Revision 1.12 2004/08/01 01:21:17 bernie * LIKELY(), UNLIKELY(): New compiler-specific macros. * @@ -256,9 +259,29 @@ /* Simple macros */ -#define ABS(a) (((a) < 0) ? -(a) : (a)) -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#if GNUC_PREREQ(2,0) + #define ABS(n) ({ \ + __typeof__(n) _n = (n); \ + (_n < 0) ? -_n : _n; \ + }) + #define MIN(a,b) ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + (void)(&_a == &_b); /* ensure same type */ \ + (_a < _b) ? _a : _b; \ + }) + #define MAX(a,b) ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + (void)(&_a == &_b); /* ensure same type */ \ + (_a > _b) ? _a : _b; \ + }) +#else /* !GNUC */ + /* Buggy macros for inferior compilers */ + #define ABS(a) (((a) < 0) ? -(a) : (a)) + #define MIN(a,b) (((a) < (b)) ? (a) : (b)) + #define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif /* !GNUC */ #ifndef BV /*! Convert a bit value to a binary flag */