Prevent multiple definition of MIN/MAX

Message ID 564B61EA.7030200@linux.vnet.ibm.com
State Superseded
Delegated to: Joseph Myers
Headers

Commit Message

Paul E. Murphy Nov. 17, 2015, 5:20 p.m. UTC
  Some recent changes caused a redefinition and error when these
are unconditionally defined.  Such was caused by gmp-impl.h being
included prior.

2015-11-17  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>

	* misc/sys/param.h (MIN): Guard against an outside definition.
	(MAX): Likewise.
---
 misc/sys/param.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Joseph Myers Nov. 17, 2015, 5:25 p.m. UTC | #1
On Tue, 17 Nov 2015, Paul E. Murphy wrote:

> Some recent changes caused a redefinition and error when these
> are unconditionally defined.  Such was caused by gmp-impl.h being
> included prior.
> 
> 2015-11-17  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
> 
> 	* misc/sys/param.h (MIN): Guard against an outside definition.
> 	(MAX): Likewise.

This is an installed header, and such guards against the user defining a 
macro aren't usual in installed headers; the expectation is that if you 
include a system header, you don't define any of its macros first.  See 
the options I suggested in 
<https://sourceware.org/ml/libc-alpha/2015-11/msg00289.html>.
  

Patch

diff --git a/misc/sys/param.h b/misc/sys/param.h
index 1908b93..42aa434 100644
--- a/misc/sys/param.h
+++ b/misc/sys/param.h
@@ -99,8 +99,12 @@ 
 #define powerof2(x)     ((((x) - 1) & (x)) == 0)
 
 /* Macros for min/max.  */
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#define MAX(a,b) (((a)>(b))?(a):(b))
+#ifndef MIN
+# define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+#ifndef MAX
+# define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
 
 
 #endif  /* sys/param.h */