Thread overview
error in D website demo
Feb 05, 2008
user
Feb 06, 2008
Walter Bright
Feb 06, 2008
Saaa
Feb 06, 2008
Saaa
Feb 06, 2008
Moritz Warning
Feb 06, 2008
Saaa
February 05, 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
February 06, 2008
Thanks. Fixed.
February 06, 2008
char[] str;
char[] str1 = "abc";
str[0] = 'b';        // error, "abc" is read only, may crashAs said a few
posts below, this one is wrong as well (as far as I know)


February 06, 2008
I love monologues :/


February 06, 2008
On Wed, 06 Feb 2008 08:29:22 +0100, Saaa wrote:

> char[] str;
> char[] str1 = "abc";
> str[0] = 'b';        // error, "abc" is read only, may crashAs said a
> few posts below, this one is wrong as well (as far as I know)

Where do you saw this?
February 06, 2008
"Moritz Warning" <moritzwarning@_nospam_web.de> wrote in message news:foddam$25te$1@digitalmars.com...
> On Wed, 06 Feb 2008 08:29:22 +0100, Saaa wrote:
>
>> char[] str;
>> char[] str1 = "abc";
>> str[0] = 'b';        // error, "abc" is read only, may crashAs said a
>> few posts below, this one is wrong as well (as far as I know)
>
> Where do you saw this?

http://www.digitalmars.com/d/1.0/arrays.html

special array types