[英]warning in macro that print a value
I have the following macro 我有以下宏
I want to print a variable name then the value, so the macro will help having the variable name to show then its value 我想先打印一个变量名然后显示值,所以宏将帮助让变量名先显示其值
the result of my example show 我的例子展示的结果
var = 1.234
printed on the screen. var = 1.234
打印在屏幕上。
#include <stdio.h>
#define str(s) #s
#define PRINTER(X) printf("% 12s = % f\n", str(X), X);
int main()
{
float var = 1.234f;
PRINTER(var);// <===== warning here
return EXIT_SUCCESS;
}
my question, if you try it, let me know if you get a warning within main, and what it mean?? 我的问题是,如果您尝试尝试,请告诉我是否在main中收到警告,这意味着什么? for me I get flag ` ' used with type `s'
对我来说,我得到flag ` ' used with type `s'
edit:
flag description 标志说明
(space) If no sign is going to be written, a blank space is inserted before the value. (空格)如果不写任何符号,则在值之前插入一个空格。
Сhange Сhange
#define PRINTER(X) printf("% 12s = % f\n", str(X), X);
to 至
#define PRINTER(X) printf("%12s = %f\n", str(X), X);`
Notice the space removed between %
and specifier. 注意%
和说明符之间的空格已删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.