title: Is it legal write to a byte array in a union and read from an int to convert values in MISRA C?
body: <p>I guess this must have been asked before, but I could not get a specific yes/no answer.</p>
  
  <p>I have this code snippet :</p>
  
  <pre><code>union integer_to_byte
  {
      signed int  IntPart;
      unsigned char BytePart[2];
  };
  
  typedef union integer_to_byte I2B;
  
  main()
  {
     I2B u16VarNo;
  
     while(1)
     {
         // some code....
         u16VarNo.BytePart[1]= P1;
  
         // some more code ....
         u16VarNo.BytePart[0]= P2;
  
         // still more code ...
         if(u16VarNo.IntPart != 0xFFFF)
         {
         }
     }
  }
  </code></pre>
  
  <p>Is this a legal way to use Unions in C ? From what I read; only the last assigned Union part is valid.So <em>"u16VarNo.BytePart[1]"</em> is not determinate ?
  The code which I have written works perfectly as expected,but I thought I would get it clarified.</p>
  
  <p>TIA.</p>