SAL at Microsoft

bearophile bearophileHUGS at lycos.com
Mon Feb 28 04:36:04 PST 2011


> But I don't understand how a __format_string annotation helps here.
> 
> If you have code like this:
> 
> string f = "%d";
> writeln(f, 10);
> 
> Adding that annotation (here translated to a D annotation) doesn't help the compiler much:
> 
> @format_string string f = "%d";
> writeln(f, 10);

There's a bug there, the code needs to be:

@format_string string f = "%d";
writefln(f, 10);

In most cases you don't want to print a format string, so if you write:

@format_string string f = "%d";
writeln(f, 10);

The compiler is probably able to show a warning, that says that you are using a format string as first argument of a printing function that doesn't use a format string :-) And this warning is enough to catch that bug.

Bye,
bearophile


More information about the Digitalmars-d mailing list