Macro in C
If the macro name appears inside its own expansion, then it is not expanded.
So don't try to write recursive macros like this one ...
#define FACTORIAL(k) k==0?1 : k*FACTORIAL(k-1);
This is Incorrect....
#include<stdio.h>
#include<conio.h>
#define MAX(FNAME,DTYPE)
DTYPE FNAME(DTYPE x,DTYPE y)
{
return x>y?x:y;
}
MAX(max_int ,int)
MAX(max_float ,float)
MAX(max_double ,double)
int main(void)
{
int p;
float q;
double r;
p=max_int(3,9);
q=max_float(7.4,5.7);
r=max_double(12.34,13.54);
printf("p=%d, q=%f ,r=%2lf \n",p,q,r);
return 0;
}
If the macro name appears inside its own expansion, then it is not expanded.
So don't try to write recursive macros like this one ...
#define FACTORIAL(k) k==0?1 : k*FACTORIAL(k-1);
This is Incorrect....
#include<stdio.h>
#include<conio.h>
#define MAX(FNAME,DTYPE)
DTYPE FNAME(DTYPE x,DTYPE y)
{
return x>y?x:y;
}
MAX(max_int ,int)
MAX(max_float ,float)
MAX(max_double ,double)
int main(void)
{
int p;
float q;
double r;
p=max_int(3,9);
q=max_float(7.4,5.7);
r=max_double(12.34,13.54);
printf("p=%d, q=%f ,r=%2lf \n",p,q,r);
return 0;
}
No comments:
Post a Comment