Text in D article
Pierre Rouleau
prouleau at impathnetworks.com
Sat Nov 18 10:27:16 PST 2006
Pierre Rouleau wrote:
> Daniel Keep wrote:
>
>> Here's a draft of an article which, hopefully, will explain some of the
>> details of how text in D works. Any constructive criticism is welcomed,
>> along with edits or corrections.
>>
>
> As someone who has not been coding in D except for trying out some D
> every so often, I find:
>
> - the discussion of Unicode and its support of D clear and useful
> - the description of the use of printf and string confusing:
>
> You wrote::
>
> Back before D had the std.stdio.writefln method, most examples used
> the old C function printf. This worked fine until you tried to output
> a string::
>
> printf(“Hello, World!\n”);
>
> The above statement was very likely to print out garbage that left
> many people scratching their heads. The reason is that C uses
> NUL-terminated strings, whereas D uses true arrays. In other words:
>
> - Strings in C are a pointer to the first character. A string ends at
> the first NUL character.
> - Strings in D are a pointer to the first character, followed by a
> length. There is no terminating character.
>
> And that's the problem: printf is looking for a terminator that
> doesn't necessarily exist.
>
>
> That would lead me to believe that I could not use printf to print a
> string litteral. But then I just wrote and compiled the following D code::
>
> int
> main()
> {
> printf("Hello!\n");
> printf("Bye!\n");
> return 1;
> }
>
> But it prints just fine. So, something must be missing in your
> explanation or my understanding. I'll have to read more about D to
> understand.
>
> Just my 2 cents,
>
> --
> P.R.
>
>
And BTW, the line::
printf(“Hello, World!\n”);
does not compile because of the non ASCII characters used for quoting.
So other questions comes to mind:
- Can D source code contain Unicode characters freely?
- If so, how is it done?
- If not, how can we define a Unicode string literal?
- Does D have a Unicode string type like, say Python, or is it better at
specifying them?
- How do we handle internationalization of presentation strings in D?
- gettext support...
- Do we have to use text codecs (as in Python for example)?
This information would fit quite nicely in an article describing text in D.
More information about the Digitalmars-d
mailing list