title: Segmentation fault: 11 when returning stuct via function pointer in struct
body: <p>I'm trying to emulate a constructor. I'm attempting to do this by having a parent Struct have a function pointer that returns a pointer to a child struct. Any help would be much appreciated.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "stdlib.h"
  
  typedef struct child_t {
  
    char *name;
  
  } Child;
  
  typedef struct parent_t {
  
    Child (*NewChild)();
  
  } Parent;
  
  Child *NewChild() {
    Child *child = malloc(sizeof(Child));
  
    child-&gt;name = "foo";
  
    return child;
  }
  
  int 
  main()
  {
    Parent parent;
  
    Child child = parent.NewChild();
  }
  </code></pre>