Hi guys, there's a question about macro:
Is there a macro can implement get the mininum number from 2 numbers, but the macro support the parameter with "++". like :
1 2 3 4 5 6 7 8
#define MIN(a, b) .......
int main(void)
{
int i = 5, j = 6;
return MIN(i++, j); /* i only plus 1 */
}
No, the macros are stupid
eg: #define MIN( a, b ) ( a < b ? a : b )
When calling return MIN ( i++, j ); the code actually becomes ( i++ < j ? i++ : j )
Macros simply perform cut & paste on your sourcecode and they are more C than C++
C++ allows inlined functions:
1 2
template < class T >
inline T min ( const T &a, const T &b ) { return a < b ? a : b; }