我在if宏中有一个typedef ,类似于:
#ifdef BLA_BLA
typedef int typeA
#elseif
typedef double tyeA
#endif
printf("%d" , a); printf("%l" , a);
Run Code Online (Sandbox Code Playgroud)
我想知道在为这种情况编写printf时最好的方法是什么?(%d或%l).
我知道我也可以在宏中定义一个固定的字符串.但这是最好的方式吗?
使用宏来定义格式字符串.
#ifdef BLA_BLA
typedef int typeA;
#define FORMAT "%d"
#elseif
typedef double typeA;
#define FORMAT "%f"
#endif
...
typeA a = ...;
printf("Hello " FORMAT " there", a); printf(FORMAT , a);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1085 次 |
| 最近记录: |