title: A variable value is different when it is printed after structural assignment and when printed without the structural assignment
body: <p>I do not know how to put an appropriate title to explain the problem. Thus feel free if you have a more informative title to edit.</p>
  
  <p>To understand the problem, let me explain what I am doing. </p>
  
  <p>I have created a structure as following: </p>
  
  <pre><code>typedef union __attribute__ ((__packed__)) adcs_measurements_t
  {
      unsigned char raw[72];
      struct __attribute__ ((__packed__)) //191
      {
          int magneticFieldX : 16;
          int magneticFieldY : 16;
          int magneticFieldZ : 16;
          int coarseSunX : 16;
          int coarseSunY : 16;
          int coarseSunZ : 16;
          int sunX : 16;
          int sunY : 16;
          int sunZ : 16;
          int nadirX : 16;
          int nadirY : 16;
          int nadirZ : 16;
          int XAngularRate : 16;
          int YAngularRate : 16;
          int ZAngularRate : 16;
          int XWheelSpeed : 16;
          int YWheelSpeed : 16;
          int ZWheelSpeed : 16;
          int star1BX : 16;
          int star1BY : 16;
          int star1BZ : 16;
          int star1OX : 16;
          int star1OY : 16;
          int star1OZ : 16;
          int star2BX : 16;
          int star2BY : 16;
          int star2BZ : 16;
          int star2OX : 16;
          int star2OY : 16;
          int star2OZ : 16;
          int star3BX : 16;
          int star3BY : 16;
          int star3BZ : 16;
          int star3OX : 16;
          int star3OY : 16;
          int star3OZ : 16;
      } fields;
  } adcs_measurements_t;
  </code></pre>
  
  <p>I populate the structure by calling a function as following: </p>
  
  <pre><code>void adcsTM191_measurements(adcs_measurements_t* dataOut)
  {
      int pass;
      unsigned char TMID = 191;
      unsigned char readBuff[72] = {0};
      pass = I2C_write(ADCS_ADDR, &amp;TMID, 1);
      if(pass != 0)
      {
          printf("write error %d\n", pass);
      }
      pass = I2C_read(ADCS_ADDR, readBuff, 72);
      if(pass != 0)
      {
          printf("read error %d\n", pass);
      }
  
      dataOut-&gt;fields.magneticFieldX = (readBuff[1] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[0] &amp; 0x00FF);
      dataOut-&gt;fields.magneticFieldY = (readBuff[3] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[2] &amp; 0x00FF);
      dataOut-&gt;fields.magneticFieldZ = (readBuff[5] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[4] &amp; 0x00FF);
      dataOut-&gt;fields.coarseSunX = (readBuff[7] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[6] &amp; 0x00FF);
      dataOut-&gt;fields.coarseSunY = (readBuff[9] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[8] &amp; 0x00FF);
      dataOut-&gt;fields.coarseSunZ = (readBuff[11] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[10] &amp; 0x00FF);
      dataOut-&gt;fields.sunX = (readBuff[13] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[12] &amp; 0x00FF);
      dataOut-&gt;fields.sunY = (readBuff[15] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[14] &amp; 0x00FF);
      dataOut-&gt;fields.sunZ = (readBuff[17] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[16] &amp; 0x00FF);
      dataOut-&gt;fields.nadirX = (readBuff[19] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[18] &amp; 0x00FF);
      dataOut-&gt;fields.nadirY = (readBuff[21] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[20] &amp; 0x00FF);
      dataOut-&gt;fields.nadirZ = (readBuff[23] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[22] &amp; 0x00FF);
      dataOut-&gt;fields.XAngularRate = (readBuff[25] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[24] &amp; 0x00FF);
      dataOut-&gt;fields.YAngularRate = (readBuff[27] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[26] &amp; 0x00FF);
      dataOut-&gt;fields.ZAngularRate = (readBuff[29] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[28] &amp; 0x00FF);
      dataOut-&gt;fields.XWheelSpeed = (readBuff[31] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[30] &amp; 0x00FF);
      dataOut-&gt;fields.YWheelSpeed = (readBuff[33] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[32] &amp; 0x00FF);
      dataOut-&gt;fields.ZWheelSpeed = (readBuff[35] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[34] &amp; 0x00FF);
      dataOut-&gt;fields.star1BX = (readBuff[37] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[36] &amp; 0x00FF);
      dataOut-&gt;fields.star1BY = (readBuff[39] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[38] &amp; 0x00FF);
      dataOut-&gt;fields.star1BZ = (readBuff[41] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[40] &amp; 0x00FF);
      dataOut-&gt;fields.star1OX = (readBuff[43] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[42] &amp; 0x00FF);
      dataOut-&gt;fields.star1OY = (readBuff[45] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[44] &amp; 0x00FF);
      dataOut-&gt;fields.star1OZ = (readBuff[47] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[46] &amp; 0x00FF);
      dataOut-&gt;fields.star2BX = (readBuff[49] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[48] &amp; 0x00FF);
      dataOut-&gt;fields.star2BY = (readBuff[51] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[50] &amp; 0x00FF);
      dataOut-&gt;fields.star2BZ = (readBuff[53] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[52] &amp; 0x00FF);
      dataOut-&gt;fields.star2OX = (readBuff[55] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[54] &amp; 0x00FF);
      dataOut-&gt;fields.star2OY = (readBuff[57] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[56] &amp; 0x00FF);
      dataOut-&gt;fields.star2OZ = (readBuff[59] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[58] &amp; 0x00FF);
      dataOut-&gt;fields.star3BX = (readBuff[61] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[60] &amp; 0x00FF);
      dataOut-&gt;fields.star3BY = (readBuff[63] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[62] &amp; 0x00FF);
      dataOut-&gt;fields.star3BZ = (readBuff[65] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[64] &amp; 0x00FF);
      dataOut-&gt;fields.star3OX = (readBuff[67] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[66] &amp; 0x00FF);
      dataOut-&gt;fields.star3OY = (readBuff[69] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[68] &amp; 0x00FF);
      dataOut-&gt;fields.star3OZ = (readBuff[71] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[70] &amp; 0x00FF);
  
  }
  </code></pre>
  
  <p>Finally I print, for instance <code>YWheelSpeed</code>. </p>
  
  <pre><code>adcsTM191_measurements(&amp;temp);  
  printf("structure y wheel speed is: %d \n", temp.fields.YWheelSpeed);
  </code></pre>
  
  <p>This value should print a negative value and it does:</p>
  
  <pre><code>structure y wheel speed is: -97
  </code></pre>
  
  <p>Now here is the thing, if I print <code>(readBuff[27] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[26] &amp; 0x00FF)</code>, which corresponds to what was populated inside the Y wheel speed variable,  anywhere inside <code>adcsTM191_measurements(adcs_measurements_t* dataOut)</code> it does not print this negative value. Rather it prints the maximum value of an unsigned char (65,535‬). </p>
  
  <pre><code>int y = (int) (readBuff[33] &amp; 0x00FF) &lt;&lt; 8 | (readBuff[32] &amp; 0x00FF);
  printf("inside struct y is: %d", y);
  </code></pre>
  
  <p>I am expecting that storing inside the structure does a kind of implicit cast and so it prints the negative value as expected. How is it doing it? How can I print the correct value without the use of the structure? </p>