[Mesa-dev] [PATCH 1/3] st/mesa: use MIN2 macro in favour of custom _min function

Erik Faye-Lund kusmabite at gmail.com
Mon Feb 24 14:54:53 PST 2014


On Sat, Feb 22, 2014 at 1:34 AM, Ian Romanick <idr at freedesktop.org> wrote:
> On 02/21/2014 03:15 PM, Marek Olšák wrote:
>>
>> The main reason _min exists is that it evaluates each parameter once,
>> while MIN2 evaluates each parameter twice, so in this case, MIN2 calls
>> the get_param function twice, which may not be desirable. The same for
>> the other macros.
>
>
> There is a GCC extension that cope with this, but I don't know if other
> compilers support it.  It has existed in GCC for a decade or more. Directly
> from the GCC documentation:
>
>      #define max(a,b) \
>        ({ typeof (a) _a = (a); \
>            typeof (b) _b = (b); \
>          _a > _b ? _a : _b; })
>
> If some variation of this works with MSVC, maybe we could just "fix" our
> MIN2 and MAX2 macros.

It doesn't seem to work on MSVC 2012, at least. There's decltype[1]
which is similar to typeof, but it doesn't seem like it's too happy
about stuffing compount statements inside function call parameter
lists etc.

[1] http://msdn.microsoft.com/en-us/library/dd537655.aspx


More information about the mesa-dev mailing list