discuss-gnustep
[Top][All Lists]
Advanced

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

Re: definition of MAX and MIN Macros


From: David Ayers
Subject: Re: definition of MAX and MIN Macros
Date: Thu, 24 Aug 2006 14:59:31 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20060724)

Marc Brünink schrieb:
> Hi all,
> 
> This Code does not work on Solaris 10 x86:
> #define MIN(a,b) \
>       ({typeof(a) _MIN_a = (a); typeof(b) _MIN_b = (b);  \
>         _MIN_a < _MIN_b ? _MIN_a : _MIN_b; })
> 
> But this one does:
> #define MIN(a,b) ( a < b ? a : b)
> 
> So why the heck do we use all this typeof stuff?

To insure that a and b are not evaluated more than once when the macro
is expanded:

val = MIN(i++,--j); /* Or insert any method invokation that changes
state.  */

Try using __typeof__ which I believe may be more portable.

Cheers,
David





reply via email to

[Prev in Thread] Current Thread [Next in Thread]