title: How to check whether all bytes in a memory block are zero
body: <p>I have a block of memory with elements of fixed size, say 100 bytes, put into it one after another, all with the same fixed length, so memory looks like this </p>
  
  <pre><code>&lt;element1(100 bytes)&gt;&lt;element2(100 bytes)&gt;&lt;element3(100 bytes)&gt;...
  </code></pre>
  
  <p>In some situations I need to determine whether all bytes of a certain element are set to the 0-byte because that has a special meaning (I didn't say it was a good idea, but that is the situation I am in).</p>
  
  <p>The question is, how do I do that efficiently. Further: is there a simple function to do it. For setting bytes to zero I can used memset or bzero, but I don't know of any function for checking for zero.</p>
  
  <p>At the moment I am using a loop for the check</p>
  
  <pre><code>char *elementStart = memoryBlock + elementNr*fixedElementSize;
  bool special = true;
  for ( size_t curByteNr=0; curByteNr&lt;fixedElementSize; ++curByteNr )
  {
    special &amp;= (*(elementStart+curByteNr)) == 0;
  }
  </code></pre>
  
  <p>Of course, I could loop with a bigger offset and check several bytes at once with a mword or some other suited bigger type. And I guess that would be rather efficient, but I would like to know whether there is a function to take that burden from me.</p>
  
  <p>Suggested functions:</p>
  
  <ul>
  <li>!memcmp (compareBlock, myBlock, fixedElementSize)</li>
  </ul>