bug-gnulib
[Top][All Lists]
Advanced

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

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


From: Bruno Haible
Subject: [bug-gnulib] Re: gcc -Wall warning for minmax.h
Date: Mon, 23 May 2005 11:21:22 +0200
User-agent: KMail/1.5

Paul Eggert wrote:
> Second, suppose <limits.h> and <sys/param.h> have conflicting
> definitions of MIN and MAX?  To work around the latter potential
> problem you can #undef MIN and MAX after including <limits.h>.

In this case we'll still get warnings, either when the user does

   #include <stdint.h>
   #include <limits.h>

or when he does

   #include <stdint.h>
   #include <sys/param.h>

Since the first case is more probable (because <limits.h> comes from a
more generic standard than <sys/param.h>), I'll just take the definition
from <limits.h> in this case, and ignore <sys/param.h>.

I therefore commit this patch.

Bruno


*** lib/minmax.h.bak    2003-09-29 10:33:09.000000000 +0200
--- lib/minmax.h        2005-05-22 22:49:38.000000000 +0200
***************
*** 1,5 ****
  /* MIN, MAX macros.
!    Copyright (C) 1995, 1998, 2001, 2003 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
--- 1,5 ----
  /* MIN, MAX macros.
!    Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
***************
*** 24,31 ****
     #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>
  
  /* 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
--- 24,38 ----
     #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 if <limits.h> is
!    included after this file.  Likewise for <sys/param.h>.
!    If more than one of these system headers define MIN and MAX, pick just
!    one of the headers (because the definitions most likely are the same).  */
! #if HAVE_MINMAX_IN_LIMITS_H
! # include <limits.h>
! #elif HAVE_MINMAX_IN_SYS_PARAM_H
! # 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
*** m4/minmax.m4.bak    2005-05-22 22:43:10.000000000 +0200
--- m4/minmax.m4        2005-05-22 23:09:58.000000000 +0200
***************
*** 0 ****
--- 1,38 ----
+ # 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],
+ [
+   AC_REQUIRE([gl_PREREQ_MINMAX])
+ ])
+ 
+ # Prerequisites of lib/minmax.h.
+ AC_DEFUN([gl_PREREQ_MINMAX],
+ [
+   gl_MINMAX_IN_HEADER([limits.h])
+   gl_MINMAX_IN_HEADER([sys/param.h])
+ ])
+ 
+ dnl gl_MINMAX_IN_HEADER(HEADER)
+ AC_DEFUN([gl_MINMAX_IN_HEADER],
+ [
+   define([header],[translit([$1],[./-],
+                                  [___])])
+   define([HEADER],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                                  [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+   AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
+     [gl_cv_minmax_in_]header,
+     [AC_TRY_COMPILE([#include <$1>
+ int x = MIN (42, 17);], [],
+        [gl_cv_minmax_in_]header[=yes],
+        [gl_cv_minmax_in_]header[=no])])
+   if test $gl_cv_minmax_in_[]header = yes; then
+     AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
+       [Define to 1 if <$1> defines the MIN and MAX macros.])
+   fi
+   undefine([HEADER])
+   undefine([header])
+ ])






reply via email to

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