title: (C) Pointer not properly evaluation dereference operator
body: <p>I am working on a project for school and I have managed to figure out a work around by doing something really clunky with my code. I have a structure that holds multiple fields, and I am trying to access the following field (as it is declared in the struct named current_event).</p>
  
  <pre><code>int *number_of_couples;
  </code></pre>
  
  <p>and later down into the program I call this value so I can dynamically allocate an array based on this *number_of_couples field. Essentially I am trying to use this as a "length" operator as C does not have (good) solution.</p>
  
  <p>Before I was trying to implement the following code: </p>
  
  <pre><code>int *permutable_array;
  permutable_array = malloc((current_event-&gt;number_of_couples) * sizeof(int)); //Line 91
  if(permutable_array == NULL){
      panic("permutable_array"); //Ensures that Malloc was successful. 
  }
  </code></pre>
  
  <p>which would in turn throw the following error:
  Line 91: error: invalid operands to binary * (have 'int *' and 'unsigned int')</p>
  
  <p>I have made a very sloppy work around because at this point I just want to get the program working (hour three of pure programming! rock on!). So I implemented:</p>
  
  <pre><code>int *permutable_array;
  int avoid_my_bug = (int) current_event-&gt;number_of_couples;
  permutable_array = malloc(avoid_my_bug * sizeof(int));
  if(permutable_array == NULL){
      panic("permutable_array");
  }
  </code></pre>
  
  <p>Which works. Now I somewhat understand the error that it is telling me. I suspect it has something to do with the fact that I stored the value of number_of_couples as a pointer within current_event, which is also a pointer. So really if the value of number_of_couples is 4, the path the program makes to get to that value is:</p>
  
  <pre><code>ptr_to_current_event -&gt; ptr_to_number_of_couples -&gt; 4
  </code></pre>
  
  <p>I can use my sloppy work-around, but it is obvious that I am doing it to avoid a bug. I would rather learn why the code will not compile. I also tried doing:</p>
  
  <pre><code>permutable_array = malloc((*current_event-&gt;number_of_couples) * sizeof(int)); //Line 91
  </code></pre>
  
  <p>which should have dereferenced the pointer returned by current_event->number_of_couples, however it crashes. Any solutions?</p>
  
  <p>*<strong><em>EDIT</em>*</strong>
  It is initialized by the following line of code:</p>
  
  <pre><code>fscanf(input_file, "%i", &amp;current_event-&gt;number_of_couples);
  </code></pre>
  
  <p>and is referenced at least three times (there is a valid int value stored in it) by the program before reaching my code. Remember, the second bit works, therefore it is definitely initialized. </p>