[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] MIN, MAX and ABS
From: |
Oskar Liljeblad |
Subject: |
[Bug-gnulib] MIN, MAX and ABS |
Date: |
Sat, 27 Sep 2003 19:15:42 +0200 |
User-agent: |
Mutt/1.5.4i |
minmax.h defines MIN and MAX macros like this:
#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
#endif
While the gcc solution is nice, don't most people assume that
MAX/MIN behaves like the second case? I know this has been
discussed before (see
http://mail.gnu.org/archive/html/bug-gnulib/2003-01/msg00077.html),
but I'd like to reopen the case...
A solution would be to use lower case min and max to be like it
is defined above.
Also, an ABS macro here would be useful as well:
#undef ABS
#define ABS(a) (((a) < 0) ? -(a) : (a))
#ifndef abs
# if __STDC__ && defined __GNUC__ && __GNUC__ >= 2
# define abs(a) (__extension__ \
({__typeof__ (a) _a = (a); \
_a < 0 ? -_a : _a; \
}))
# else
# define abs(a,b) (((a) < 0) ? -(a) : (a))
# endif
#endif
Regards,
Oskar Liljeblad (address@hidden)
- [Bug-gnulib] MIN, MAX and ABS,
Oskar Liljeblad <=