Copy a struct on the heap and get the pointer to it.

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Nov 12 07:27:38 PST 2011


On 11/12/11 9:22 AM, kenji hara wrote:
> Here is a pitfall.
> If S has the postblit, it is not called with your code.
>
> import core.stdc.stdio;
> struct S
> {
>      this(this){
>          printf("postblit\n");
>      }
> }
> void main()
> {
>      S s;
>      S* ps = [s].ptr;
>      // does not print "postblit"
> }
>
> I've already poted a pull
> (https://github.com/D-Programming-Language/dmd/pull/375) to fix it,
> but it is not yet merged.

Thanks! This is important. I recall C++ was much more difficult to use 
in the period of time where compilers got various copy construction 
scenarios wrong. We need to have object copying rock-solid.

Andrei




More information about the Digitalmars-d mailing list