error in D website demo

user at domain.invalid user at domain.invalid
Tue Feb 5 10:42:52 PST 2008


Hi,

I just started playing with D and noticed an error when I build the 
"Hello World" program on the website at 
http://www.digitalmars.com/d/2.0/index.html. Such errors are often 
perplexing to new users :-).

Line 23 of the demo is:

         writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv);

But it produces incorrect output:

Hello World, Reloaded
1st arg: %sC:\Documents and Settings\DennisC\My Documents\My Source 
Files\D\hello\hello.exe

Notice the %s floating in the output.

This is because the library was changed as documented at 
http://www.digitalmars.com/d/2.0/phobos/std_stdio.html. Its description 
of writef() says:

IMPORTANT:
New behavior starting with D 2.006: unlike previous versions, writef 
(and also writefln) only scans its first string argument for format 
specifiers, but not subsequent string arguments. This decision was made 
because the old behavior made it unduly hard to simply print string 
variables that occasionally embedded percent signs.


So it seems to me that this line should be rewritten as either:

         writefln(cl.argnum, cl.suffix, " arg: ", cl.argv);

or

         writefln("%d%s arg: %s", cl.argnum, cl.suffix, cl.argv);

to be compatible with the current library behavior.

HTH
Dennis Cote



More information about the Digitalmars-d mailing list