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

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



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.

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 ?

--
Vincent Rivière