hackish writefln? and

david ta-nospam-zz at gmx.at
Sat Apr 28 13:02:50 PDT 2007


david schrieb:
> Hello all!
> 
> Is
>     writefln( (i<10?" ":"") ~ "%d: %s", i, v);
> 
> supposed to work, according to the specs?
> Just looked at them, but couldn't quiet get it.
> 
> But nevertheless it *does* work,
> no compile/runtime error and it acts
> also in the expected way.
> 
> BUT: I just came back from hunting (bugs),
> and you get an error if you write the above code
> in a file, read it in using std.file & std.stream,
> and writefln it back to the console:
> 
> *** bugtest.txt
> writefln( (i<10?" ":"") ~ "%d: %s", i, v);
> 
> *** bugtest.d
> import std.file, std.stream, std.stdio;
> void main()
> {
>     File file = new File;
>     file.open("bugtest.txt");
>     char[] line;
>     line = file.readLine();
>     file.close();
>     writefln(line);        // here we get an error
> }
> 
> 
> david

Just confirmed:
*** bug.d
import std.stdio;
void main()
{
	char[] line;
	line = "writefln( (i<10?\" \":\"\") ~ \"%d: %s\", i, v);";
	writefln(line);		// here we get an error
}

It compiles just fine, so the string should be ok, BUT at runtime:
Error: std.formatwritefln( (i<10?" ":"") ~ "

david


More information about the Digitalmars-d-learn mailing list