need help

Anders F Björklund afb at algonet.se
Tue Apr 25 07:05:54 PDT 2006


Deewiant wrote:

>>That's usually not a good idea(unchecked format strings...)
> 
> Huh? In what kind of situation are the following two not equivalent?

When the string contains format characters (that would be '%')

> writef("%s", s);
> writef(s);
> 
> Regardless of the type of s, these surely work the same way, right?

import std.stdio;
void main()
{
   char[] s = "100%";
   writef(s);
}

==> Throws an error:
100Error: std.format invalid specifier

import std.stdio;
void main()
{
   char[] s = "100%";
   writef("%s", s);
}

==> This works OK.

I suggested adding a function "write", that *didn't* parse for format
characters (and the matching "writeln" function), but it was ignored...

import std.stdio;
void main()
{
   char[] s = "100%";
   write(s);
}

http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15627

--anders



More information about the Digitalmars-d-learn mailing list