Skip to content

Commit 10a44c8

Browse files
Add quasi-sane abs() implementation to Arduino.h (earlephilhower#157)
As mentioned in earlephilhower#156 (comment)
1 parent a55fac8 commit 10a44c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cores/rp2040/Arduino.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636

3737
#include "debug_internal.h"
3838

39+
// Try and make the best of the old Arduino abs() macro. When in C++, use
40+
// the sane std::abs() call, but for C code use their macro since stdlib abs()
41+
// is int but their macro "works" for everything (with potential side effects)
42+
#ifdef abs
43+
#undef abs
44+
#endif // abs
45+
#ifdef __cplusplus
46+
using std::abs;
47+
#else
48+
#define abs(x) ((x)>0?(x):-(x))
49+
#endif
50+
3951
#ifdef __cplusplus
4052
extern "C"{
4153
#endif // __cplusplus

0 commit comments

Comments
 (0)