digitalmars.D - writef is good, printf is bad
- MicroWizard (11/11) Feb 20 2005 printf is old, bad and ugly. Theoretically it is correct. Let's try writ...
- John Reimer (5/22) Feb 20 2005 I don't get that runtime error using writefln() with a firstpartk="".
- Derek (24/41) Feb 20 2005 DMD v0.113
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (18/28) Feb 20 2005 It was impossible to guess from your sample code,
- MicroWizard (8/18) Feb 21 2005 You got the point. I was too lazy to copy the code precisely.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/11) Feb 21 2005 Not a problem. There's another thread going in the bugs group
printf is old, bad and ugly. Theoretically it is correct. Let's try writef.
What should I do, when a char[] is actually empty (ie. null) ?
//char[] firstpart="kakukk";
char[] firstpart="";
printf("firstpart=%.*s\n",firstpart); //works, shows nothing after = sign
writefln("firstpart=%s",firstpart); //aborts and rewards with this message
Runtime error:
firstpart=Error: std.format formatArg
Could anybody show me a workaround?
Thanks in advance,
Tamas Nagy
Feb 20 2005
On Sun, 20 Feb 2005 11:44:42 +0000, MicroWizard wrote:
printf is old, bad and ugly. Theoretically it is correct. Let's try writef.
What should I do, when a char[] is actually empty (ie. null) ?
//char[] firstpart="kakukk";
char[] firstpart="";
printf("firstpart=%.*s\n",firstpart); //works, shows nothing after = sign
writefln("firstpart=%s",firstpart); //aborts and rewards with this message
Runtime error:
firstpart=Error: std.format formatArg
Could anybody show me a workaround?
Thanks in advance,
Tamas Nagy
I don't get that runtime error using writefln() with a firstpartk="".
Works fine on dmd 0.113 on Linux.
My output:
firstpart =
Feb 20 2005
On Sun, 20 Feb 2005 11:44:42 +0000 (UTC), MicroWizard wrote:
printf is old, bad and ugly. Theoretically it is correct. Let's try writef.
What should I do, when a char[] is actually empty (ie. null) ?
//char[] firstpart="kakukk";
char[] firstpart="";
printf("firstpart=%.*s\n",firstpart); //works, shows nothing after = sign
writefln("firstpart=%s",firstpart); //aborts and rewards with this message
Runtime error:
firstpart=Error: std.format formatArg
Could anybody show me a workaround?
Thanks in advance,
Tamas Nagy
DMD v0.113
<code>
import std.stdio;
void main()
{
char[] ns;
char[] es = "";
writefln("Empty String is '%s'", es);
writefln("Null String is '%s'", ns);
writefln("Lit Empty String is '%s'", "");
ns = null;
writefln("Lit Null String is '%s'", ns);
}
</code>
Output is ...
Empty String is ''
Null String is ''
Lit Empty String is ''
Lit Null String is ''
--
Derek
Melbourne, Australia
Feb 20 2005
MicroWizard wrote:printf is old, bad and ugly. Theoretically it is correct. Let's try writef. What should I do, when a char[] is actually empty (ie. null) ?It was impossible to guess from your sample code, but "null" defaults to having a type of (void*) In order for null to work with writef, it *must* have char[] type. (I think this is a bug in Phobos, as it should accept "null" too ?)char[] firstpart=""; writefln("firstpart=%s",firstpart); //aborts and rewards with this message Runtime error: firstpart=Error: std.format formatArgAs others shown, that code is working OK. You seem to show output from another test program ? <aargh> 1.writefln("Null String is '%s'", null);Null String is 'Error: std.format formatArg 2.writefln("Empty String is '%s'", "");Empty String is '' 3.writefln("Null String is '%s'", cast(char[]) null);Null String is '' But just using "" instead of cast(char[]) null is a lot easier ? Having a null char[] variable, instead of a literal, works too. There are a still quite a few quirks in Phobos, regarding usage of "" versus null. Hopefully they can all be sorted out in time... --anders
Feb 20 2005
In article <cvabia$2vst$2 digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...1.You got the point. I was too lazy to copy the code precisely. The original type was byte[] and not char[] the automatic casting works (somehow).writefln("Null String is '%s'", null);Null String is 'Error: std.format formatArg 2.writefln("Empty String is '%s'", "");Empty String is ''But just using "" instead of cast(char[]) null is a lot easier ? Having a null char[] variable, instead of a literal, works too. There are a still quite a few quirks in Phobos, regarding usage of "" versus null. Hopefully they can all be sorted out in time...Thanks a lot. I agree, D should be grown up, and these anomalies will be solved. Tamas Nagy
Feb 21 2005
MicroWizard wrote:Not a problem. There's another thread going in the bugs group about the difference (or the lack thereof) between null and ""... And I do think your subject should be "writef is D, printf is C". Then again, to some people that seems to mean the same thing :-) --andersThere are a still quite a few quirks in Phobos, regarding usage of "" versus null. Hopefully they can all be sorted out in time...Thanks a lot. I agree, D should be grown up, and these anomalies will be solved.
Feb 21 2005









John Reimer <brk_6502 yahoo.com> 