by randlet · 11y ago · 0 comments
What is the advantage of this:
#define min(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
over the naive #define min(a, b) (((a) < (b)) ? (a) : (b))
? min(a++, b++);
a or b would really be incremented twice.A compiler might be able to avoid this if it can prove expensive_calcluation is pure, but this is usually not done unless WPO is in play.
(void) (&_a == &_b); \
… which makes sure that the types are actually compatible, and not just having one converted to the other.