title: The right way of implementing a constructor in C
body: <p>I want to create a constructor using C.
  What is the cleanest way to achieve this?</p>
  
  <p>My attempt:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct line {
      void (*add_line_ptr)(struct line*, int x, int y);
      int x;
      int y;
  };
  
  void add_line(struct line* lptr, int x, int y)
  {
      lptr-&gt;x = x;
      lptr-&gt;y = y;
  }
  
  
  int main()
  {
      struct line line1 = {add_line, 0, 0};
      line1.add_line_ptr(&amp;line1, 10, 20);
      printf("%d %d\n", line1.x, line1.y);
  }
  </code></pre>
  
  <p>I think that using <code>line1.add_line(&amp;line1,</code> is a bit redundant - since it's quite obvious that I want to do the operation on line1.
  Is there a way to implement this without passing a pointer to the "object"(struct)? or some other way I didn't think of?</p>