From mint-bounce@lists.fishpool.fi Mon Jan 28 07:24:48 2008 Message-ID: <479DC734.1090702@freesbee.fr> Date: Mon, 28 Jan 2008 13:14:44 +0100 From: =?ISO-8859-1?Q?Vincent_Rivi=E8re?= User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: mint Subject: Re: [MiNT] mintlib problem References: <1201516043.9694.23.camel@localhost> In-Reply-To: <1201516043.9694.23.camel@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 28 Jan 2008 12:14:21.0936 (UTC) FILETIME=[5093DF00:01C861A7] X-ecartis-version: Ecartis v1.0.0 Sender: mint-bounce@lists.fishpool.fi Errors-to: mint-bounce@lists.fishpool.fi X-original-sender: vincent.riviere@freesbee.fr Precedence: bulk List-help: List-unsubscribe: List-Id: X-List-ID: List-subscribe: List-owner: List-post: 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