bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-gnulib] MIN, MAX and ABS


From: Paul Eggert
Subject: Re: [Bug-gnulib] MIN, MAX and ABS
Date: 27 Sep 2003 15:48:50 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Oskar Liljeblad <address@hidden> writes:

> I'd like to reopen the case...

OK.  In <http://mail.gnu.org/archive/html/bug-gnulib/2003-01/msg00095.html>
Bruno okayed a patch that I never got around to installing.  I just
installed it (see below).  This addresses part of your request.

> A solution would be to use lower case min and max to be like it
> is defined above.

Surely we'll run into the same problem with lower-case min and max, as
system headers define them, too.  A quick grep through my /usr/include
finds that Xlib defines them, and PEX #undef's them with some choice
words about Xlib.

> Also, an ABS macro here would be useful as well:

Hmm, why not use the absolute-value functions of stdlib.h, inttypes.h,
math.h and tgmath.h?  Admittedly they're a bit of a mess (abs, labs,
llabs, imaxabs, fabs, fabsf, fabsl, etc.), but they're the standard
way to do it.  And they should do the right thing with NaNs and -0.0,
whereas the macro won't.


Here's what I installed.  (This patch also removes a misspelled and
redundant word from a comment.)

2003-09-27  Paul Eggert  <address@hidden>

        * minmax.h (MIN, MAX) [__STDC__ && defined __GNUC__ && __GNUC__ >= 2]:
        Omit the special code that used __typeof__, since we worry that
        it could be more trouble than it's worth.  See:
        http://mail.gnu.org/archive/html/bug-gnulib/2003-01/msg00090.html
        http://mail.gnu.org/archive/html/bug-gnulib/2003-01/msg00095.html

Index: minmax.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/minmax.h,v
retrieving revision 1.2
diff -p -u -r1.2 minmax.h
--- minmax.h    24 Jan 2003 15:25:16 -0000      1.2
+++ minmax.h    27 Sep 2003 22:32:35 -0000
@@ -27,7 +27,7 @@
    since otherwise we get redefinitions on some systems.  */
 #include <limits.h>
 
-/* Note: MIN and MAX should preferrably be used with two arguments of the
+/* 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
    arguments, if the arguments have different types or have unusual
    floating-point values.  For example, on a typical host with 32-bit 'int',
@@ -42,28 +42,12 @@
 
 /* MAX(a,b) returns the maximum of A and B.  */
 #ifndef MAX
-# if __STDC__ && defined __GNUC__ && __GNUC__ >= 2
-#  define MAX(a,b) (__extension__                                          \
-                    ({__typeof__ (a) _a = (a);                             \
-                      __typeof__ (b) _b = (b);                             \
-                      _a > _b ? _a : _b;                                   \
-                     }))
-# else
-#  define MAX(a,b) ((a) > (b) ? (a) : (b))
-# endif
+# define MAX(a,b) ((a) > (b) ? (a) : (b))
 #endif
 
 /* MIN(a,b) returns the minimum of A and B.  */
 #ifndef MIN
-# if __STDC__ && defined __GNUC__ && __GNUC__ >= 2
-#  define MIN(a,b) (__extension__                                          \
-                    ({__typeof__ (a) _a = (a);                             \
-                      __typeof__ (b) _b = (b);                             \
-                      _a < _b ? _a : _b;                                   \
-                     }))
-# else
-#  define MIN(a,b) ((a) < (b) ? (a) : (b))
-# endif
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
 #endif /* _MINMAX_H */




reply via email to

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