X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=macros.h;h=7fec0134842687a0dff87d6df2ee9c601228d154;hb=64969cdb6b48f50b642178779baf9e1e317e0645;hp=08aaa85c883289c987d573f2ea1e81551e0d1044;hpb=fd3f7490acdd11c16df7530089ca18785fd63915;p=bertos.git diff --git a/macros.h b/macros.h index 08aaa85c..7fec0134 100755 --- a/macros.h +++ b/macros.h @@ -14,6 +14,12 @@ /*#* *#* $Log$ + *#* Revision 1.10 2005/01/22 04:19:50 bernie + *#* Use non-uglified typeof(). + *#* + *#* Revision 1.9 2004/12/08 08:51:34 bernie + *#* Add type-generic macros for C++. + *#* *#* Revision 1.8 2004/10/19 07:14:20 bernie *#* Add macros to test for specific compiler features. *#* @@ -60,21 +66,30 @@ #include -#if (COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) - /* Type-generic macros */ +/* avr-gcc does not seem to support libstdc++ */ +#if defined(__cplusplus) && !CPU_AVR + /* Type-generic macros implemented with template functions. */ + #include + + template inline T ABS(T n) { return n >= 0 ? n : -n; } + #define MIN(a,b) std::min(a, b) + #define MAX(a,b) std::max(a, b) + #define SWAP(a,b) std::swap(a, b) +#elif (COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) + /* Type-generic macros implemented with statement expressions. */ #define ABS(n) ({ \ - __typeof__(n) _n = (n); \ + typeof(n) _n = (n); \ (_n < 0) ? -_n : _n; \ }) #define MIN(a,b) ({ \ - __typeof__(a) _a = (a); \ - __typeof__(b) _b = (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); \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ (void)(&_a == &_b); /* ensure same type */ \ (_a > _b) ? _a : _b; \ }) @@ -88,7 +103,10 @@ /*! Bound \a x between \a min and \a max. */ #define MINMAX(min,x,max) (MIN(MAX(min, x), max)) -#if COMPILER_TYPEOF +#ifdef __cplusplus + /* Use standard implementation from */ + #define SWAP(a,b) std::swap(a, b) +#elif COMPILER_TYPEOF /*! * Type-generic macro to swap \a a with \a b. *