Dec 30, 2009 at 11:53am Dec 30, 2009 at 11:53am UTC
Why do you prefer macros?
Dec 30, 2009 at 12:04pm Dec 30, 2009 at 12:04pm UTC
It takes just one line. Are functions faster than macros ?
Dec 30, 2009 at 12:27pm Dec 30, 2009 at 12:27pm UTC
Thanks for the link.
It's necessary to use inline functions or simple functions like MAX(a, b) ? inlines are faster ?
Dec 30, 2009 at 12:53pm Dec 30, 2009 at 12:53pm UTC
R0mai wrote:Why do you prefer macros?
littleprogrammer wrote:It takes just one line
int MAX (int a, int b) { return (a > b) ? a : b; }
Last edited on Dec 30, 2009 at 12:53pm Dec 30, 2009 at 12:53pm UTC
Dec 30, 2009 at 1:07pm Dec 30, 2009 at 1:07pm UTC
@Bazzy: you're right, I got wrong ...
Thanks both . :)
Dec 31, 2009 at 12:49am Dec 31, 2009 at 12:49am UTC
@littleprogrammer:
Just run this code and then tell me macros are better:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#define MAXIMUM( a, b ) a > b ? a : b
int main() {
int a = 4;
int b = 6;
int c = MAXIMUM( a++, b );
std::cout << a << ", " << b << ", " << c << std::endl;
}
An inline function is exactly as fast as a macro.
EDIT: removed extra semicolon at end of macro definition as pointed out by PanGalactic
Last edited on Dec 31, 2009 at 3:11am Dec 31, 2009 at 3:11am UTC