源代碼如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define max_t(type, x, y) ({ \
type __max1 = (x); \
type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; })
int main(int argc, char* argv[])
{
float a = max_t(float, -13.12, -14.21);
float b = max_t(float, 13.12, 14.21);
int c = max_t(int, -13, -14);
int d = max_t(int, 13, 14);
printf("a=%f\n", a);
printf("b=%f\n", b);
printf("c=%d\n", c);
printf("d=%d\n", d);
return 0;
}
運行結果如下所示:
a=-13.120000
b=14.210000
c=-13
d=14