On 11/29/11 13:32, Eric Blake wrote:
>>    #if FEATURE_ENABLED
>> >     #define FEATURE_FORMAT "feature"
>> >    #else
>> >     #define FEATURE_FORMAT ""
>> >    #endif
>> >    ...
>> >    printf (buf, FEATURE_FORMAT);
> I assume you meant sprintf (buf, FEATURE_FORMAT), or printf
> (FEATURE_FORMAT)?

Yes, that's right.

Since my earlier example wasn't convincing enough, how
about this one?

#if FEATURE_ENABLED
 #define FEATURE_FORMAT_ARGS(a, b) "(%d, %s)" a, b
#else
 #define FEATURE_FORMAT_ARGS(a, b) ""
#endif
...
printf (FEATURE_FORMAT_ARGS (i, argv[i]);
...
snprintf (buf, sizeof buf, FEATURE_FORMAT_ARGS (i, argv[i]);

I wouldn't mind so much if I thought that -Wformat-zero-length
would be useful, but I can't think of a single likely
use case for it.  It's not like there's a real problem with
people writing 'printf ("");' when they should write nothing.


Reply via email to