bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] gcc -Wall warning for minmax.h


From: Derek Price
Subject: Re: [bug-gnulib] gcc -Wall warning for minmax.h
Date: Tue, 17 May 2005 12:43:41 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Paul Eggert wrote:

>Derek Price <address@hidden> writes:
>
>
>  
>
>>+#ifdef LIMITS_H_HAS_MINMAX
>>+# include <limits.h>
>>+#elif SYS_PARAM_H_HAS_MINMAX
>>+# include <sys/param.h>
>>+#endif
>>    
>>
>
>This doesn't work if <limits.h> and <sys/param.h> both define MIN.
>  
>

Hrm.  Okay, I've fixed this, though I think such a system that is also
broken with respect to the current "minmax.h" (where <limits.h> _and_
<sys/param.h> both define MIN _without protecting the definitions with
#ifndef MIN_) is not likely to occur in practice since it would require
a system where the order of inclusion of <limits.h> and <sys/param.h>
mattered.

>>+  AC_CHECK_HEADERS_ONCE([sys/param.h],
>>+    [gl_have_sys_param_h=:], [gl_have_sys_param_h=false])dnl
>>    
>>
>
>You don't need to check whether sys/param.h exists.  All you
>need to do is to see whether the following program compiles:
>
>#include <sys/param.h>
>int x = MIN (1, 2);
>
>Similarly for <limits.h>.  You shouldn't need to use EGREP_CPP.
>  
>

Okay, I see that now.  Fixed.

Corrected patch attached.

Regards,

Derek
Index: m4/minmax.m4
===================================================================
RCS file: m4/minmax.m4
diff -N m4/minmax.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/minmax.m4        17 May 2005 16:44:20 -0000
@@ -0,0 +1,31 @@
+# minmax.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_MINMAX], [gl_PREREQ_MINMAX])
+
+# Prerequisites of minmax.h.
+AC_DEFUN([gl_PREREQ_MINMAX],
+[
+  AC_COMPILE_IFELSE(
+[#include <limits.h>
+int x = MIN (1, 2);],
+    [gl_limits_h_has_minmax=:], [gl_limits_h_has_minmax=false])
+
+  if $gl_limits_h_has_minmax; then
+    AC_DEFINE(LIMITS_H_HAS_MINMAX, 1,
+      [Define to 1 if <limits.h> defines the MIN and MAX macros.])
+  else
+    AC_COMPILE_IFELSE(
+[#include <sys/param.h>
+int x = MIN (1, 2);],
+      [gl_sys_param_h_has_minmax=:], [gl_sys_param_h_has_minmax=false])
+
+    if $gl_sys_param_h_has_minmax; then
+      AC_DEFINE(SYS_PARAM_H_HAS_MINMAX, 1,
+       [Define to 1 if <sys/param.h> defines the MIN and MAX macros.])
+    fi
+  fi
+  :])
Index: lib/minmax.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/minmax.h,v
retrieving revision 1.4
diff -u -p -r1.4 minmax.h
--- lib/minmax.h        14 May 2005 06:03:58 -0000      1.4
+++ lib/minmax.h        17 May 2005 16:44:20 -0000
@@ -23,9 +23,15 @@
    MIN, MAX macro redefinitions on some systems; the workaround is to
    #include this file as the last one among the #include list.  */
 
-/* Before we define the following symbols we get the <limits.h> file
-   since otherwise we get redefinitions on some systems.  */
-#include <limits.h>
+/* Before we define the following symbols we try to get the <limits.h>
+   or <sys/param.h> files since otherwise we get redefinitions on some
+   systems.  */
+#ifdef LIMITS_H_HAS_MINMAX
+# include <limits.h>
+#endif
+#ifdef SYS_PARAM_H_HAS_MINMAX
+# include <sys/param.h>
+#endif
 
 /* Note: MIN and MAX should be used with two arguments of the
    same type.  They might not return the minimum and maximum of their two
Index: modules/minmax
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/minmax,v
retrieving revision 1.3
diff -u -p -r1.3 minmax
--- modules/minmax      28 Sep 2004 20:15:39 -0000      1.3
+++ modules/minmax      17 May 2005 16:44:20 -0000
@@ -3,10 +3,12 @@ MIN, MAX macros.
 
 Files:
 lib/minmax.h
+m4/minmax.m4
 
 Depends-on:
 
 configure.ac:
+gl_MINMAX
 
 Makefile.am:
 lib_SOURCES += minmax.h

reply via email to

[Prev in Thread] Current Thread [Next in Thread]