In <clcm-20040122-> Barry Schwarz <> writes:
>On Thu, 22 Jan 2004 13:05:00 +0200, "nfg" <> wrote:
>
>>Is there a way to comment out part of a format string used in i.e. printf,
>>sprintf, etc? What I have in mind is a statement like printf("%s %s %s",
>>string1, string2, string3), and the temporary need to eliminate one format
>>specifier (%s) and its corresponding string: printf("%s %s /* %s */",
>>string1, string2, /*string3*/). Now, while coomenting out string3 works
>>fine, obviously the comment delimiters /* and */ around %s do not get
>>accepted as such. Workarounds, anyone?
>>
>If the comment string is a literal as in your example, then the answer
>is no because you are not allowed to modify a string literal at any
>time.
Note that he doesn't want to do it at run time and there is nothing wrong
in modifying a string literal with a text editor
The solution is ugly, but it is possible:
printf("%s %s " /* "%s" */, string1, string2 /*, string3*/);
It works because comments get replaced by white space in TP3, while
adjacent string literal splicing occurs in TP6. To uncomment it, it is
enough to remove the /* and */.
I would comment out the whole printf call, though:
/* printf("%s %s %s", string1, string2, string3); */
printf("%s %s ", string1, string2);
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
--
comp.lang.c.moderated - moderation address: