need help
xs0
xs0 at xs0.com
Tue Apr 25 06:59:49 PDT 2006
Deewiant wrote:
> Thomas Kuehne wrote:
>> That's usually not a good idea(unchecked format strings...)
>
> Huh? In what kind of situation are the following two not equivalent?
>
> writef("%s", s);
> writef(s);
>
> Regardless of the type of s, these surely work the same way, right?
>
> Some test code to argue my point:
>
> --
> import std.stdio;
>
> template func(TYPE) { void func(TYPE s) {
> writef("'", s, "'");
> writef(" and ");
> writef("'%s'", s);
> writefln();
> }}
>
> class Foo {
> char[] toString() { return "fooclass"; }
> }
>
> void main() {
> func("asdf");
> func(1234);
> func(true);
> func('n');
> func(0.1234);
> func(new Foo());
> }
> --
>
> In func's output, what's on the left side of the "and" is the same as on the
> right, in all six cases.
func("%s%s%s");
:)
xs0
More information about the Digitalmars-d-learn
mailing list