Skip to content

Commit 97b9c44

Browse files
authored
Merge pull request #789 from danieltr3s/minmax_stdlib_fix
Prevent min and max macro definitions from colliding with the stdlib ones.
2 parents 4dde563 + 67e1be5 commit 97b9c44

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

STM32F1/cores/maple/wirish_math.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,21 @@ long random(long min, long max);
105105
#define SERIAL 0x0
106106
#define DISPLAY 0x1
107107

108-
#define min(a,b) ((a)<(b)?(a):(b))
109-
#define max(a,b) ((a)>(b)?(a):(b))
108+
#ifdef __cplusplus
109+
#include <algorithm>
110+
using std::min;
111+
using std::max;
112+
#else // C
113+
#include <stdlib.h>
114+
#ifndef min
115+
#define min(a,b) ((a)<(b)?(a):(b))
116+
#endif // min
117+
118+
#ifndef max
119+
#define max(a,b) ((a)>(b)?(a):(b))
120+
#endif // max
121+
#endif // __cplusplus
122+
110123
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
111124
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
112125
#define radians(deg) ((deg)*DEG_TO_RAD)

STM32F4/cores/maple/wirish_math.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,21 @@ long random(long min, long max);
9191
#define DEG_TO_RAD 0.017453292519943295769236907684886
9292
#define RAD_TO_DEG 57.295779513082320876798154814105
9393

94-
#define min(a,b) ((a)<(b)?(a):(b))
95-
#define max(a,b) ((a)>(b)?(a):(b))
94+
#ifdef __cplusplus
95+
#include <algorithm>
96+
using std::min;
97+
using std::max;
98+
#else // C
99+
#include <stdlib.h>
100+
#ifndef min
101+
#define min(a,b) ((a)<(b)?(a):(b))
102+
#endif // min
103+
104+
#ifndef max
105+
#define max(a,b) ((a)>(b)?(a):(b))
106+
#endif // max
107+
#endif // __cplusplus
108+
96109
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
97110
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
98111
#define radians(deg) ((deg)*DEG_TO_RAD)

0 commit comments

Comments
 (0)