title: struct bit field in C
body: <p>I am having this structure</p>
  <pre><code> typedef struct {
  
    uint8_t sw_reset                 : 1;
    uint8_t ble                      : 1;
    uint8_t if_inc                   : 1;
    uint8_t sim                      : 1;
    uint8_t pp_od                    : 1;
    uint8_t h_lactive                : 1;
    uint8_t bdu                      : 1;
    uint8_t boot                     : 1;
  
  } lsm6dsl_ctrl3_c_t;
  </code></pre>
  <p>This the main</p>
  <pre><code>    int main()
  {
      lsm6dsl_ctrl3_c_t   ctrl3_c;
  
      ctrl3_c.sw_reset   = 0;
      ctrl3_c.ble        = 1;
      ctrl3_c.if_inc     = 1;
      ctrl3_c.sim        = 1;
      ctrl3_c.pp_od      = 1;
      ctrl3_c.h_lactive  = 1;
      ctrl3_c.bdu        = 1;
      ctrl3_c.boot       = 1;
  
      printf(&quot;ctrl3_c 0x%x\n&quot;, ctrl3_c);
  
      return 0;
  }
  </code></pre>
  <p>when i compile, i have this warning</p>
  <pre><code>warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'lsm6dsl_ctrl3_c_t {aka struct &lt;anonymous&gt;}' [-Wformat=]
  </code></pre>
  <p>output is</p>
  <pre><code>ctrl3_c 0x4019fe
  </code></pre>
  <p>How can i fix the warning?  I was expecting 0xfe output but got 0x4019fe.  And, how can I assign the 0xfe to an uint8_t variable?</p>