简体   繁体   中英

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.

#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?? for me I get 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM