Add fallback min/max for compilers that don't have statement expressions
authorMichael Forney <mforney@mforney.org>
Mon, 17 Jun 2019 00:05:30 +0000 (17:05 -0700)
committerMichael Forney <mforney@mforney.org>
Thu, 6 Feb 2020 04:30:39 +0000 (20:30 -0800)
Statement expressions are a GNU C extension and are not available
in ISO C.

On compilers that don't have them, define these macros as plain
conditional expressions, since they are only ever used with expressions
that have no side-effects.

The statement-expression version is still retained as an added
safety measure on GNU-compatible compilers.

Signed-off-by: Michael Forney <mforney@mforney.org>
libevdev/libevdev-util.h

index c6e1197..56881a6 100644 (file)
@@ -34,6 +34,7 @@
 
 #undef min
 #undef max
+#ifdef __GNUC__
 #define min(a,b) \
                ({ __typeof__ (a) _a = (a); \
                  __typeof__ (b) _b = (b); \
                  __typeof__ (b) _b = (b); \
                _a > _b ? _a : _b; \
                })
+#else
+#define min(a,b) ((a) > (b) ? (b) : (a))
+#define max(a,b) ((a) > (b) ? (a) : (b))
+#endif
 
 static inline bool
 startswith(const char *str, size_t len, const char *prefix, size_t plen)