title: Casting one struct pointer to another - C
body: <p>Please consider the following code.</p>
  
  <pre><code>enum type {CONS, ATOM, FUNC, LAMBDA};
  
  typedef struct{
    enum type type;
  } object;
  
  typedef struct {
    enum type type;
    object *car;
    object *cdr;
  } cons_object;
  
  object *cons (object *first, object *second) {
    cons_object *ptr = (cons_object *) malloc (sizeof (cons_object));
    ptr-&gt;type = CONS;
    ptr-&gt;car = first;
    ptr-&gt;cdr = second;
    return (object *) ptr;
  }
  </code></pre>
  
  <p>In the <code>cons</code> function, variable <code>ptr</code> is of type <code>cons_object*</code>. But in the return value it is converted to type of <code>object*</code>. </p>
  
  <ol>
  <li>I am wondering how this is possible because <code>cons_object</code> and <code>object</code> are different structs. </li>
  <li>Are there any issues in doing stuff like this?</li>
  </ol>
  
  <p>Any thoughts!</p>