c printf用于宏定义类型

Gre*_*rey 1 c

我在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).

我知道我也可以在宏中定义一个固定的字符串.但这是最好的方式吗?

Mat*_*Mat 7

使用宏来定义格式字符串.

#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)