Implicit static->dynamic arr and modifying
    Nick Sabalausky via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed May  7 08:41:09 PDT 2014
    
    
  
On 5/6/2014 6:46 PM, Rene Zwanenburg wrote:
> On Tuesday, 6 May 2014 at 02:17:06 UTC, Nick Sabalausky wrote:
>> So all is well, and deliberately so. Pardon the noise.
>
> IMO it's not. I once had a particularly nasty bug because of this:
>
> struct S
> {
>      @safe:
>      string str;
>
>      this(string data)
>      {
>          import std.digest.md;
>          str = md5Of(data).toHexString(); // Oops...
>      }
> }
That must be a terribly subtle one, I'm not seeing the problem at all.
I get that md5Of returns a static array, and then a slice of it gets 
passed to toHexString, but AIUI toHexString finishes (and returns a 
newly allocated string) before the temporary static array leaves scope.
    
    
More information about the Digitalmars-d-learn
mailing list