title: Casting a pointer in C
body: <p>I created a function which returns a pointer to an object of a self-made structure. Then, I declared another pointer which I set equal to a pointer returned by the the aforementioned function. I get the error "Assignment makes pointer from integer without a cast" - but I do not understand why I should be casting... because all of these pointers were declared to be of the same type.</p>
  
  <p>In disk.h I defined the following:</p>
  
  <pre><code>struct generic_attribute{
      char *name;
      int current_value;
      int previous_value;
      //int time_series[500];
  };
  </code></pre>
  
  <p>In disk.c, I made a constructor for generic_attribute like so:</p>
  
  <pre><code>#include "disk.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdarg.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  struct generic_attribute* construct_generic_attribute(char* name, int current_value){
      struct generic_attribute *ga_ptr;
      //ga_ptr = (struct generic_attribute*) malloc (sizeof(struct generic_attribute));
      ga_ptr = malloc (sizeof (struct generic_attribute));
      ga_ptr -&gt; name = name;
      ga_ptr -&gt; current_value = current_value;
      ga_ptr -&gt; previous_value = 0;
      return ga_ptr;
  }
  </code></pre>
  
  <p>In disk_test.c I want to test this constructor:</p>
  
  <pre><code>#include "disk.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdarg.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void test_generic_attribute_constructor(char* name, int current_value){
      struct generic_attribute* ga_ptr;
      ga_ptr = construct_generic_attribute(name, current_value);
      printf("%i\n", construct_generic_attribute(name, current_value));
  }
  
  int main() {
      test_generic_attribute_constructor("test", 2000);
  }
  </code></pre>
  
  <p>I get the error on this line:</p>
  
  <pre><code>ga_ptr = construct_generic_attribute(name, current_value);
  </code></pre>
  
  <p>I do not understand why. <code>ga_pointer</code> was declared as a pointer to type <code>struct generic_attribute</code>. So was the return of function <code>construct_generic_attribute</code>. I am new to C, so I might be misunderstanding how all of this works. </p>