View Single Post
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 11-03-2006 , 09:52   Re: The Preprocessor (#if, #include, #pragma, etc.)
Reply With Quote #5

It's also very interesting that you can do FANCY stuff using function-like macros

Code:
#define MIN(%1,%2) ( ((%1) < (%2)) ? (%1) : (%2))


MIN(5, 6) evaluates to:

( ( (5) < (6) ) ? (5) : (6) )
(damn, I can't see whether I've got enough parenthesis even with those spaces!!)
Thus evaluating to 5.

Of course, HARDCORE C Programmers notice immediately: THIS IS TEH SHIT because if you pass ++i, ++i will appear twice in the preprocessor output, thus i will be incremented twice if one of the code paths is taken and only once if the other one is taken. That's why you might want to always mark function-like preprocessor macro using CAPS LOCK (or by holding shift while writing the macro name).

Greetings,
PM
__________________
hello, i am pm
PM is offline