title: Use of macros in array definition in C
body: <p>I am new to C and using it to program a Nordic nrf52 chip.  I believe my problem is a general C one though rather than application.</p>
  
  <p>I am setting up an array of structs using macros predefined in the chip SDK.  Using those macros in the array initialisation works, but doing element by element does not.<br>
  So, the following works:</p>
  
  <pre><code>nrf_twi_mngr_transfer_t transfers_1[2] = { \
                                      NRF_TWI_MNGR_WRITE(MSBARO5X_0_ADDR , &amp;reg_addr[1], 1, NRF_TWI_MNGR_NO_STOP), \
                                      NRF_TWI_MNGR_READ (MSBARO5X_0_ADDR , &amp;p_buffer[0], sizeof(p_buffer), 0)
                              };      
  </code></pre>
  
  <p>Where: </p>
  
  <pre><code>typedef struct {
      uint8_t * p_data;     ///&lt; Pointer to the buffer holding the data.
      uint8_t   length;     ///&lt; Number of bytes to transfer.
      uint8_t   operation;  ///&lt; Device address combined with transfer direction.
      uint8_t   flags;      ///&lt; Transfer flags (see @ref NRF_TWI_MNGR_NO_STOP).
  } nrf_twi_mngr_transfer_t;
  </code></pre>
  
  <p>NRF_TWI_WRITE and _READ are macros that use further macros, for example:</p>
  
  <pre><code>#define NRF_TWI_MNGR_WRITE(address, p_data, length, flags) \
      NRF_TWI_MNGR_TRANSFER(NRF_TWI_MNGR_WRITE_OP(address), p_data, length, flags)
  </code></pre>
  
  <p>which uses</p>
  
  <pre><code>#define NRF_TWI_MNGR_WRITE_OP(address)      (((address) &lt;&lt; 1) | 0)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>#define NRF_TWI_MNGR_TRANSFER(_operation, _p_data, _length, _flags) \
  {                                      \
      .p_data    = (uint8_t *)(_p_data), \
      .length    = _length,              \
      .operation = _operation,           \
      .flags     = _flags                \
  }
  </code></pre>
  
  <p>What I want to do is change individual items in this array, for example:</p>
  
  <pre><code>transfers_1[0] = NRF_TWI_MNGR_WRITE(MSBARO5X_0_ADDR , &amp;reg_addr[1], 1, NRF_TWI_MNGR_NO_STOP);
  </code></pre>
  
  <p>However when I do that, I get the error "expected an expression".</p>
  
  <p>MSBARO5X_0_ADDR is also defined in a define statement:
      #define MSBARO5X_0_ADDR         0x76</p>
  
  <p>If I replace this in any of the above code with a variable, I get the same "expected an expression" error.  I suspect the two problems I have are due to the same lack of understanding on my part.  SO forgive me for combining the two in a single post.</p>
  
  <p>So the questions are:
  -Why am I getting this error?
  -Is it possible to change individual items in my array, and if so how?
  -Is it possible to use a variable in place of the MSBARO5X_ADDR, and if so how?</p>
  
  <p>Many thanks!</p>