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

Re: [MiNT] sys/param.h change for GCC 4 compatibility



On Sun, 2008-01-13 at 23:51 +0100, Vincent Rivière wrote:
> Alan Hourihane wrote :
> > Here's a patch to MiNTlibs sys/param.h so that GCC 4 is happy too.
> 
>  > /* Macros for min/max.  */
>  > -#ifndef MIN
>  > -#define MIN(a,b) \
>  > -    ({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b);     \
>  > -	      _a < _b ? _a : _b; })
>  > -#endif
>  > -#ifndef MAX
>  > -#define MAX(a,b) \
>  > -    ({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b);  \
>  > -	      _a > _b ? _a : _b; })
>  > -#endif
>  > +#define MIN(a,b) (((a)<(b))?(a):(b))
>  > +#define MAX(a,b) (((a)>(b))?(a):(b))
> 
> Sorry but I have no problem with the current implementation.
> Furthermore, it avoids multiple evaluation of the arguments, unlike the 
> traditional implementation you propose.

Well, the glibc includes specify the above so that's where I checked
before posting.

> However, I have a warning when compiling with -pedantic:
> warning: ISO C forbids braced-groups within expressions
> 
> It can be avoided by inserting __extension__ before the body of the macros :
> #define MIN(a,b) \
>      __extension__({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \
> 	      _a < _b ? _a : _b; })
> 
> This technique is used for the traps in <osbind.h>.
> 
> Did you find something else wrong ?

No, but I'm happy with either way. But it needs fixing so applications
that use MIN/MAX definitions don't barf.

Alan.