From 06ef34c86bc9c50ac18063121be761d99f816636 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 16 Jun 2019 17:05:30 -0700 Subject: [PATCH] Add fallback min/max for compilers that don't have statement expressions 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 --- libevdev/libevdev-util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libevdev/libevdev-util.h b/libevdev/libevdev-util.h index c6e1197..56881a6 100644 --- a/libevdev/libevdev-util.h +++ b/libevdev/libevdev-util.h @@ -34,6 +34,7 @@ #undef min #undef max +#ifdef __GNUC__ #define min(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ @@ -44,6 +45,10 @@ __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)