title: Initializing Array of Structure in C
body: <p>I have the following structure </p>
  
  <pre><code>typedef struct {
      int buf[BUF_SIZE]; // the buffer
      size_t len; // number of items in the buffer
      pthread_mutex_t mutex; // needed to add/remove data from the buffer
      pthread_cond_t can_produce; // signaled when items are removed
      pthread_cond_t can_consume; // signaled when items are added
  };
  </code></pre>
  
  <p>Initially I was simply initializing it as follows</p>
  
  <pre><code>buffer_t buffer = {
      .len = 0,
      .mutex = PTHREAD_MUTEX_INITIALIZER,
      .can_produce = PTHREAD_COND_INITIALIZER,
      .can_consume = PTHREAD_COND_INITIALIZER
  };
  </code></pre>
  
  <p>Although I would like to initialize an array of buffer_t with those values, although I'm not quite sure how to properly do it.</p>
  
  <p>Something like </p>
  
  <pre><code>buffer_t buffer[NUM_ARRAY] = {
      .len = 0,
      .mutex = PTHREAD_MUTEX_INITIALIZER,
      .can_produce = PTHREAD_COND_INITIALIZER,
      .can_consume = PTHREAD_COND_INITIALIZER
  };
  </code></pre>
  
  <p>(Which I realize is incorrect)</p>
  
  <p>Edit: I ended up using </p>
  
  <pre><code>buffer_t buffers[NUM_THREADS];
  
  for (i = 0, i &lt; 3, i ++) {
         buffers[i] = (buffer_t) {
                  .len = 0,
                  .mutex = PTHREAD_MUTEX_INITIALIZER,
                  .can_produce = PTHREAD_COND_INITIALIZER,
                  .can_consume = PTHREAD_COND_INITIALIZER
              };  
  }
  </code></pre>