C实现的泛型
程序代码:
#include <stdio.h>
#define PRINT(type,x,format) do{printf("%"format,(type)x);}while(0)
int main(void)
{
PRINT(int,20,"d");
return 0;
}
程序代码:
#include <stdio.h>
#define PRINT(type,x,format) do{printf("%"format,(type)x);}while(0)
int main(void)
{
PRINT(int,20,"d");
return 0;
}
2008-06-19 09:11
2008-06-19 09:23
2008-06-19 09:27
2008-06-19 09:31
2008-06-19 09:36

2008-06-19 09:42
程序代码:
#include <stdio.h>
#define PRINT(type,x,format) do{\
type tmp=x;\
printf("%"format,(type)tmp);}\
while(0)
int main(void)
{
PRINT(char*,"hello","s\n");
//PRINT(char,"hello error","s\n");//编译产生警告
PRINT(double,'c',"c\n");
PRINT(int,'c',"c\n");
//PRINT(int,999999999999999,"f\n");//编译产生警告
PRINT(double,999999999999999,"f\n");
return 0;
}

2008-06-20 09:02
2008-06-20 15:25
2008-06-20 15:26

2008-06-20 16:18