Interesting bug with std.random.uniform and dchar

Joseph Rushton Wakeling via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 8 07:48:38 PDT 2014


On 08/06/14 16:25, monarch_dodra via Digitalmars-d-learn wrote:
> Arguably, the issue is the difference between "invalid" and downright "illegal"
> values. The thing about dchar is that while it *can* have values higher than
> dchar max, it's (AFAIK) illegal to have them, and the compiler (if it can) will
> flag you for it:
>
> dchar c1 = 0x0000_D800; //Invalid, but fine.
> dchar c2 = 0xFFFF_0000; //Illegal, nope.

Yup.  If you use an invalid wchar (say, via writeln), you'll get a nonsense 
symbol on your screen, but it will work.  Try and writeln a dchar whose value is 
greater than dchar.max and you'll get an exception/error thrown.


More information about the Digitalmars-d-learn mailing list