Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
October 06, 2004 [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Attachments: | Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). Thomas |
October 06, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | Thomas Kuehne wrote:
> Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted.
>
> Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword).
>
> Thomas
shouldn't
writef(msg,"\n");
be
writefln("",msg);
otherwise the msg gets parsed as a format string.
|
October 06, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | Ben Hinkle wrote:
> Thomas Kuehne wrote:
>
>> Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted.
>>
>> Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword).
>>
>> Thomas
>
> shouldn't
> writef(msg,"\n");
> be
> writefln("",msg);
> otherwise the msg gets parsed as a format string.
What's wrong with
writefln(msg);
?
Stewart.
|
October 06, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
> Ben Hinkle wrote:
>
>> Thomas Kuehne wrote:
>>
>>> Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted.
>>>
>>> Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword).
>>>
>>> Thomas
>>
>> shouldn't
>> writef(msg,"\n");
>> be
>> writefln("",msg);
>> otherwise the msg gets parsed as a format string.
>
> What's wrong with
>
> writefln(msg);
>
> ?
>
> Stewart.
I haven't actually tried it but yeah that might work as long as there aren't any parameters. I don't know if writef errors when it sees writef("%s") with an error saying not enough parameters or if it prints the string "%s". To be consistent it should error but I don't know what it actually does. -Ben
|
October 06, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
<snip>
>> shouldn't
>> writef(msg,"\n");
>> be
>> writefln("",msg);
>> otherwise the msg gets parsed as a format string.
>
>
> What's wrong with
>
> writefln(msg);
Oops, that wasn't what I meant to say.
You misunderstand how writef works. Unlike printf, writef doesn't just take its first argument to be a format string.
Instead, it takes the first string it encounters to be a format string. It then reads as many arguments as the format string specifies. After it has done this, it reads subsequent argument strings in the same way, which may include another format string.
And so either
writefln("", msg);
or
writefln(msg);
will cause msg to be interpreted as a format string. OTOH, if you write
writefln("%s", msg);
then msg is a field of the format string "%s". Hence msg will not be parsed as a format string.
Stewart.
|
October 06, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | On Wed, 06 Oct 2004 13:08:48 +0100, Stewart Gordon wrote: > Ben Hinkle wrote: > >> Thomas Kuehne wrote: >> >>> Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. >>> >>> Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). >>> >>> Thomas >> >> shouldn't >> writef(msg,"\n"); >> be >> writefln("",msg); >> otherwise the msg gets parsed as a format string. > > What's wrong with > > writefln(msg); > > ? > > Stewart. The first parameter is supposed to be a template or pattern, thus if 'msg' just happens to contain formatting codes, the application may abort. It is safer to do ... writefln("%s", msg); I tested 'writefln("%s")' and I got the error message "Error: std.format". -- Derek Melbourne, Australia |
October 07, 2004 Re: [Patch] phobos: replaced printf with writef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon schrieb:
> Instead, it takes the first string it encounters to be a format string.
> It then reads as many arguments as the format string specifies. After
> it has done this, it reads subsequent argument strings in the same way,
> which may include another format string.
>
> And so either
>
> writefln("", msg);
>
> or
>
> writefln(msg);
>
> will cause msg to be interpreted as a format string. OTOH, if you write
>
> writefln("%s", msg);
>
> then msg is a field of the format string "%s". Hence msg will not be parsed as a format string.
I forgot that :O
Thomas
|
Copyright © 1999-2021 by the D Language Foundation