title: Setting a buffer of char* with intermediate casting to int*
body: <p>I could not fully understand the consequences of what I read here: <a href="https://stackoverflow.com/questions/4291048/casting-an-int-pointer-to-a-char-ptr-and-vice-versa">Casting an int pointer to a char ptr and vice versa</a></p>
  
  <p>In short, would this work?</p>
  
  <pre><code>set4Bytes(unsigned char* buffer) {
    const uint32_t MASK = 0xffffffff;
    if ((uintmax_t)buffer % 4) {//misaligned
       for (int i = 0; i &lt; 4; i++) {
         buffer[i] = 0xff;
       } 
    } else {//4-byte alignment
      *((uint32_t*) buffer) = MASK;
    }
  
  }
  </code></pre>
  
  <p><strong>Edit</strong><br/>
  There was a long discussion (it was in the comments, which mysteriously got deleted) about what type the pointer should be casted to in order to check the alignment. The subject is now addressed <a href="https://stackoverflow.com/questions/26160068/is-there-a-portable-way-to-know-if-uintptr-t-is-defined-in-stdint-h">here</a>.</p>