1
votes

I'm wondering if there is a nice way to avoid gcc to scream about printf types : 'warning: format ‘%d’ expects argument of type ‘int’, but argument 12 has type foo'

This is pretty anoying when you know that you wrote 'typedef int foo' somewhere ...

Of course, I'm not looking for the gcc fix for that ( [-Wformat] ).

I would like to know if there is a way to avoid the warning WITHOUT casting each time of course!

2
I'm guessing you mean that you still want to get other warnings... right? But do you want to get valid printf() warnings?Patrick87
Can you show us a code example of where you're getting a warning you think is spurious?Fred Larson

2 Answers

8
votes

If you have typedef int foo, gcc shouldn't warn you. If gcc is warning you, there's a fair chance foo really isn't an integer.

0
votes

This has Undefined Behaviour all over. Do not use!

char *fmt;
fmt = "%d%f%p%u\n";
printf(fmt, 1, 1, 1, 1, 1, 1, 1, 1, 1); /* fill stack with values */