Link to home
Start Free TrialLog in
Avatar of shahrahulb
shahrahulb

asked on

macro

i have a macro to compute max of 2 numbers
#define max2( x, y )  (x) > (y) ? (x) : (y)

similarly i can define function to same stuff
int max(int x, int y) {
  x > y ? return(x) : return(y);


what is the advantage of using macro over function
Avatar of ozo
ozo
Flag of United States of America image

macro can avoid function call overhead
function wll work with max(++x,++y)
Avatar of shahrahulb
shahrahulb

ASKER

by function call overhead, do u mean to say, storing variables in stack, save memory location etc.....

if that is the case, how macros work
ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what difference does it make if the c0de size increases
>> what difference does it make if the c0de size increases

on usual pc's it makes no difference, since memory-size is not a matter for those boxes in these days.
but imagine you develop software for pda's or mobiles or some other *mini*-computers, then it makes a
difference.

ike