From: bernie Date: Wed, 8 Dec 2004 08:51:34 +0000 (+0000) Subject: Add type-generic macros for C++. X-Git-Tag: 1.0.0~940 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=710f861d5049012cbf64d9bae757b0e917907c8c;p=bertos.git Add type-generic macros for C++. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@301 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/macros.h b/macros.h index 08aaa85c..6639d99b 100755 --- a/macros.h +++ b/macros.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* 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,8 +63,17 @@ #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); \ (_n < 0) ? -_n : _n; \ @@ -88,7 +100,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. *