title: What is the difference between unsigned char and unsigned short in this case?
body: <p>We need to upgrade our program which use unsigned char as bit mask to a newer version which use unsigned short as bit mask. I believe there is some difference between them because our program failed using same logic with unsigned char changed to unsigned short. ( That is from the external library we bought. The library upgraded so we need to change the program too ).</p>
  
  <pre><code>Old version:
  typedef struct SomeStruct {
      unsigned char   bit_mask;
  #       define      SomeStruct_a_present 0x80
  #       define      SomeStruct_b_present 0x40
  #       define      SomeStruct_c_present 0x20
      X          x;
      Y          y;
      A          a;  /* optional; set in bit_mask
                                  * SomeStruct_a_present if
                                  * present */
  
      B          b;  /* optional; set in bit_mask
                                  * SomeStruct_b_present if
                                  * present */
  
      C          c;  /* optional; set in bit_mask
                                  * SomeStruct_c_present if
                                  * present */
  } SomeStruct;
  
  
  
  New version:
  typedef struct SomeStruct {
      unsigned short   bit_mask;
  #       define      SomeStruct_x_present 0x8000
  #       define      SomeStruct_y_present 0x4000
  #       define      SomeStruct_a_present 0x2000
  #       define      SomeStruct_b_present 0x1000
  #       define      SomeStruct_c_present 0x0800
      X          x;/* optional; set in bit_mask
                                  * SomeStruct_x_present if
                                  * present */
      Y          y;/* optional; set in bit_mask
                                  * SomeStruct_y_present if
                                  * present */
      A          a;  /* optional; set in bit_mask
                                  * SomeStruct_a_present if
                                  * present */
  
      B          b;  /* optional; set in bit_mask
                                  * SomeStruct_b_present if
                                  * present */
  
      C          c;  /* optional; set in bit_mask
                                  * SomeStruct_c_present if
                                  * present */
  } SomeStruct;
  </code></pre>
  
  <p>I think there are some problem with our current line because the program crash:</p>
  
  <p>Our current method to set the bit_mask:</p>
  
  <pre><code>someStruct.bit_mask = SomeStruct_a_present;
  someStruct.bit_mask |= SomeStruct_b_present;
  someStruct.bit_mask |= SomeStruct_c_present;
  </code></pre>