title: Error[Pe142]: expression must have pointer-to-object type
body: <p>I'm coding c in IAR Embedded workbench IDE. I have the following in a header file.</p>
  
  <pre><code>typedef union {
  uint8_t payload;
  struct UBX_NAV_POSLLH  nav_posllh;
  struct UBX_NAV_STATUS  nav_status;
  struct UBX_NAV_DOP     nav_dop;
  struct UBX_NAV_SOL     nav_sol;
  struct UBX_NAV_VELNED  nav_velned; 
  struct UBX_NAV_TIMEUTC nav_timeutc;
  struct UBX_NAV_SVINFO  nav_svinfo;
  } UBXPayload;
  
  struct UBXHeader {
  uint8_t  class;
  uint8_t  id;
  uint16_t len;
  uint8_t  ck_a;
  uint8_t  ck_b;
  };
  
  struct UBXPacket {
  struct UBXHeader header;
  UBXPayload payload;
  };
  </code></pre>
  
  <p>Here is my source file:</p>
  
  <pre><code>static char *c_buffer
  void myinit( )
  {
    c_buffer= (char*)malloc(50);
  }
  int myfunc(uint8_t c, char *c_buffer)
  {
    static uint8_t rx_count = 0;
    struct UBXPacket *ubx   = (struct UBXPacket *)c_buffer;
    for(int i=0; i&lt;3; i++){        
      ubx-&gt;payload.payload[rx_count] = c; /* Error[Pe142]: expression must have pointer-  to-object type */
      rx_count++;
     }
  }
  
  void main( )
  {
    char mychar = 'h';
    myinit( );
    myfunc(mychar,  c_buffer);
  }
  </code></pre>
  
  <p>The same <strong>union</strong> is defined as follows in another code sample written to be compiled with ARM GCC compiler. It compiles well &amp; works well.</p>
  
  <pre><code>typedef union {
  uint8_t payload[0];  /* here [0] is placed */
  struct UBX_NAV_POSLLH  nav_posllh;
  struct UBX_NAV_STATUS  nav_status;
  struct UBX_NAV_DOP     nav_dop;
  struct UBX_NAV_SOL     nav_sol;
  struct UBX_NAV_VELNED  nav_velned; 
  struct UBX_NAV_TIMEUTC nav_timeutc;
  struct UBX_NAV_SVINFO  nav_svinfo;
  } UBXPayload;
  </code></pre>
  
  <p>But in IAR C compiler giving error. Any suggestions please ?
  I do not understand the following line</p>
  
  <pre><code>struct UBXPacket *ubx   = (struct UBXPacket *)c_buffer;
  </code></pre>