From 0d79f53ed591cb2e314d2db51c62f3900a956fa3 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 3 Sep 2021 17:31:28 -0400 Subject: [PATCH] common/macros: don't define min and max macros in C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Later in the series, the min macro conflicted with a C++ header file. Since the min and max macros are not useful in C++ (std::min/std::max are preferred, don't define them when building a C++ file. Don't define min_t and max_t either, they too can be replaced with std::min and std::max, which are templated / type-safe. Change-Id: I3d56d325f6508c32baba674c335c3f4ab0ecc582 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/macros.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/common/macros.h b/src/common/macros.h index 97faf0328..e9dc190aa 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -57,20 +57,30 @@ void *zmalloc(size_t len) }) #endif -#ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) -#endif -#ifndef max_t -#define max_t(type, a, b) max((type) a, (type) b) -#endif +/* + * The min and max macros are not needed in C++ (std::min and std::max are + * preferred) and they conflict with some C++ header file. Don't define them + * when compiling C++ source. + */ +#ifndef __cplusplus -#ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) -#endif +# ifndef max +# define max(a, b) ((a) > (b) ? (a) : (b)) +# endif + +# ifndef min +# define min(a, b) ((a) < (b) ? (a) : (b)) +# endif + +# ifndef max_t +# define max_t(type, a, b) max((type) a, (type) b) +# endif + +# ifndef min_t +# define min_t(type, a, b) min((type) a, (type) b) +# endif -#ifndef min_t -#define min_t(type, a, b) min((type) a, (type) b) #endif #ifndef LTTNG_PACKED -- 2.34.1