std.digest toHexString

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 16 09:21:08 PDT 2017


On Thursday, 16 March 2017 at 16:13:33 UTC, Carl Sturtivant wrote:
>     string ans = md5Of(arg).toHexString();

That is a major D design flaw biting you the same way it has 
bitten so many others.

See the red box in my documentation fork:

http://dpldocs.info/experimental-docs/std.digest.digest.toHexString.2.html

toHexString returns a static array... on the stack. Then the 
stupid language not only implicitly casts it to immutable, it 
also implicitly slices it, giving you a reference to mutable, 
temporary data pretending to be permanent, immutable data.

> If I replace md5Of(arg).toHexString() with 
> toHexString(md5Of(arg))....

That works for me though... maybe it is just a version mismatch 
or something, since toHexString is in a different module than 
md5of.


More information about the Digitalmars-d-learn mailing list