typeof运行时推断类型
#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
printf("Test typeof\n");
{
int x = 1024, y = 4096;
char a = 10, b = 20;
float j = 1.0, k = 2.0;
printf("char max is %d\n", max(a,b));
printf("int max is %d\n", max(x,y));
printf("float max is %f\n", max(j,k));
}
printf("\n");
参考输出:
Test typeof
char max is 20
int max is 4096
float max is 2.000000
|