Can't use toHexString
badlink via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 19 05:14:34 PDT 2015
On Sunday, 19 July 2015 at 12:08:18 UTC, Adam D. Ruppe wrote:
> This line is illegal:
>
>> return toHexString!(Order.decreasing)(crc.finish());
>
> The std.digest.toHexString and variants return a *static array*
> which is static data and has a scope lifetime.
>
> It is horrendous a compiler bug that allows it to implicitly
> convert to string - it should not compile because it silently
> gives bad results, escaping a reference to temporary memory
> while claiming it is immutable.
>
> Confusingly though, this line is fine:
>
>> return crcHexString(crc.finish());
>
> It is an EXTREMELY subtle difference in the function signature
> (and totally bug prone, yet the documentation doesn't call it
> out...)
> ...
Thank you very much for the explanation.
More information about the Digitalmars-d-learn
mailing list