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

Re: [MiNT] mintlib problem



Alan Hourihane wrote:
> #define MAX(a,b)                      \
> ({                                  \
>         __typeof__ (a) _a = (a);      \
>         __typeof__ (b) _b = (b);      \
>         _a > _b ? _a : _b;           \
> })
>
> enum { VALUE = MAX (1000, 10) };
>
> main()
> {
>         printf("%d\n",VALUE);
> }

cst.c:11: error: braced-group within expression allowed only inside a function

The "braced-group within expression" behaves like a function, and of course it can't be used as a static initializer for an enum.
In that case, the classic MAX definition must be used.

Some info from my Linux system:

$ grep -R [^A-Za-z_]MAX[^A-Za-z_] /usr/include
/usr/include/X11/fonts/ft.h:#define MAX(h,i) ((h) > (i) ? (h) : (i))
/usr/include/X11/Xregion.h:#define MAX(a,b) (((a) > (b)) ? (a) : (b))
/usr/include/sys/param.h:#define        MAX(a,b) (((a)>(b))?(a):(b))
/usr/include/dialog.h:#define MAX(x,y) ((x) > (y) ? (x) : (y))
/usr/include/glib-2.0/glib/gmacros.h:#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
/usr/include/jpegint.h:#define MAX(a,b) ((a) > (b) ? (a) : (b))

The MiNTLib implementation is free of side-effects.
However, it uses a GCC extension and can't be used as a static initializer.

So your first proposition was probably the best:
The MiNTLib MIN/MAX should be changed to the classic implementation.
However at least the MiNTLib code should be checked for potential side-effects.

--
Vincent Rivière