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: Marko Riedel
Subject: RE: definition of MAX and MIN Macros
Date: Thu, 24 Aug 2006 14:48:09 +0200 (CEST)

--- Marc Brünink <address@hidden> 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?
> 

Hello there,

I am no expert but the first version only evaluates its arguments once,
and hence it works correctly with expressions that have side effects. You
need the typeof to declare the temporary variables for the arguments a and
b.

Best regards,

Marko





+-------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, address@hidden |
| http://www.geocities.com/markoriedelde/index.html           |
+-------------------------------------------------------------+


                
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de




reply via email to

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