title: Assign an integer value to a struct
body: <p>I have a struct defined as:</p>
  
  <pre><code>typedef struct {
     uint8_t field1 : 6,
     uint8_t field2 : 1,
     uint8_t field3 : 1
  } myStruct;
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>myStruct s;
  </code></pre>
  
  <p>What is a safe way to assign an 8-bit value to all the fields at once, i.e.:</p>
  
  <pre><code>s = 10;
  </code></pre>
  
  <p>The compiler gives error when trying to assign like this (obviously, I'm not even implying this is the way to do it :) ).</p>
  
  <p>Would this be recommended:</p>
  
  <pre><code>uint8_t a = 10;
  s = * ((myStruct*) &amp;a);
  </code></pre>
  
  <p>?</p>