When is a Macro better than a Function ?
Rules of Thumb:- operation required is short, simple and(maybe) used in different locations (files).- operation required is short, simple and is used intensively.- operation required is performed on variety of different types.
Examples of last case:#define MAX(a,b) (((a)>(b)) ? (a) : (b))#define SWAP(type,a,b) {type t=a; (a)=(b); (b)=t;}Use:int a,b; /* assign some value… */ double x = MAX(a,b);SWAP(a,b);