title: I cannot edit instance of a nested structure in c
body: <p>My code does not work when trying to edit an instance of a nested structure. The code compiles successfully there is no error. It executes every line but it stops executing and does not finish executing when it reaches the second line below: </p>
  
  <pre><code>int numberOfProcess = 5;
  shmem-&gt;pid_queue = createQueue(numberOfProcess);
  enqueue(shmem-&gt;pid_queue, getpid()); 
  </code></pre>
  
  <p>These are the struct instances below:</p>
  
  <pre><code>SharedData *shmem;
  Queue *queue;
  </code></pre>
  
  <p>Xcode gives the following warning:</p>
  
  <pre><code>Thread 1: EXC_BAD_ACCESS
  </code></pre>
  
  <p>My struct is below</p>
  
  <pre><code>typedef struct {
      int front, rear, size;
      unsigned capacity;
      int* array;
  } Queue;
  
  
  typedef struct {
          int shmInt;
          int timeSec;
          int timeNanosec;
          Queue *shmMsgSec_queue;
          Queue *shmMsgNanosec_queue;
          int items_in_queue;
          sem_t mutex;
          Queue *pid_queue;
  } SharedData;
  </code></pre>
  
  <p>There are functions that manipulates queue shown below:</p>
  
  <pre><code>Queue* createQueue(unsigned capacity)
  {
       Queue* queue = ( Queue*) malloc(sizeof( Queue));
      queue-&gt;capacity = capacity;
      queue-&gt;front = queue-&gt;size = 0;
      queue-&gt;rear = capacity - 1;  // This is important, see the enqueue
      queue-&gt;array = (int*) malloc(queue-&gt;capacity * sizeof(int));
      return queue;
  }
  
  int isFull( Queue* queue)
  {  return (queue-&gt;size == queue-&gt;capacity);  }
  
  int isEmpty( Queue* queue)
  {  return (queue-&gt;size == 0); }
  
  void enqueue( Queue* queue, int item)
  {
      if (isFull(queue))
          return;
      queue-&gt;rear = (queue-&gt;rear + 1)%queue-&gt;capacity;
      queue-&gt;array[queue-&gt;rear] = item;
      queue-&gt;size = queue-&gt;size + 1;
      printf("%d enqueued to queue\n", item);
  }
  
  
  int dequeue( Queue* queue)
  {
      if (isEmpty(queue))
          return INT_MIN;
      int item = queue-&gt;array[queue-&gt;front];
      queue-&gt;front = (queue-&gt;front + 1)%queue-&gt;capacity;
      queue-&gt;size = queue-&gt;size - 1;
      return item;
  }
  
  int front( Queue* queue)
  {
      if (isEmpty(queue))
          return INT_MIN;
      return queue-&gt;array[queue-&gt;front];
  }
  
  int rear( Queue* queue)
  {
      if (isEmpty(queue))
          return INT_MIN;
      return queue-&gt;array[queue-&gt;rear];
  }
  </code></pre>