Skip to content

Commit b260115

Browse files
committed
fixed: fixed conflicts between min max and other libraries
1 parent d412d26 commit b260115

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

cores/arduino/Arduino.h

+31-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,38 @@ void loop( void ) ;
9898
#ifdef abs
9999
#undef abs
100100
#endif // abs
101+
// undefine stdlib's abs if encountered
102+
#ifdef abs
103+
#undef abs
104+
#endif // abs
105+
106+
#ifdef __cplusplus
107+
template<class T, class L>
108+
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
109+
{
110+
return (b < a) ? b : a;
111+
}
112+
113+
template<class T, class L>
114+
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
115+
{
116+
return (a < b) ? b : a;
117+
}
118+
#else
119+
#ifndef min
120+
#define min(a,b) \
121+
({ __typeof__ (a) _a = (a); \
122+
__typeof__ (b) _b = (b); \
123+
_a < _b ? _a : _b; })
124+
#endif
125+
#ifndef max
126+
#define max(a,b) \
127+
({ __typeof__ (a) _a = (a); \
128+
__typeof__ (b) _b = (b); \
129+
_a > _b ? _a : _b; })
130+
#endif
131+
#endif
101132

102-
/// conflict with STL min/max
103-
#define min(a,b) ((a)<(b)?(a):(b))
104-
#define max(a,b) ((a)>(b)?(a):(b))
105133
#define abs(x) ((x)>0?(x):-(x))
106134
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
107135
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

0 commit comments

Comments
 (0)