might be a bug in the DMD FrontEnd
Daniel Keep
daniel.keep.lists at gmail.com
Fri Mar 30 02:36:43 PDT 2007
Deewiant wrote:
> Daniel Keep wrote:
>> Davidl wrote:
>>> i don't see what prevent the following from compiling:
>> I can see a few things...
>
> <...>
>
>> cast(char)192, whilst technically valid, is really nasty. For starters,
>> '192' isn't a valid character by itself in UTF-8, which means it can't
>> be printed.
>
> <...>
>
>> Please don't use printf, at least not without passing the string through
>> toStringz. writefln works perfectly fine.
>
> Perhaps he's using printf because he wants to output the byte 192 without
> getting an "Error: 4invalid UTF-8 sequence". I've found that, currently, in both
> Phobos and Tango, the C library is the best way of outputting a character whilst
> letting the user worry about whether he can see it properly in his locale or not.
>
> The point about toStringz still stands, though.
True; I hadn't considered that. The first thing I thought was that he
didn't know about Unicode literals, and was trying to manually encode
the character in UTF-16.
That said, I personally think that if you need to use printf because
writefln is barfing on your string, then that's a bug in your program.
char[] is UTF-8: if you're not storing UTF-8, you should be using
ubyte[], not char[].
Incidentally, since D source must be either ASCII or some variant of
UTF, cast(char)192 isn't a valid character *anyway*, unless it's part of
a multibyte code-point, at which point the argument for outputting it
literally falls apart since he's using it in a mixin :P
Also, I just realised that the "you can't cast arrays of chars around"
is something I should add to my text in D article...
-- Daniel
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list