title: Can I use memcmp to check struct for non-zero members?
body: <p>I am using a large struct with many members, and I would like an easy way to quickly see if any of the members are non-zero. I know that <code>memcmp()</code> should not be used to compare two structs for equality (as explained here: <a href="https://stackoverflow.com/questions/141720/how-do-you-compare-structs-for-equality-in-c">How do you compare structs for equality in C?</a>), but I am hoping that by comparing a struct to a block of memory that has been set to 0, this may work.</p>
  
  <p>For example, assume I have some struct:</p>
  
  <pre><code>typedef struct {
      int Int1;
      int Int2;
      int Int3;
  } MyInts;
  </code></pre>
  
  <p>I create a variable from this struct:</p>
  
  <pre><code>MyInts MyStruct = {0};
  </code></pre>
  
  <p>Throughout execution of my program, the members of <code>MyStruct</code> will usually be 0, but may occasionally be set to some non-zero value temporarily. I want to quickly check if any of the ints in <code>MyStruct</code> are non-zero. Can I use <code>memcmp()</code> as below?</p>
  
  <pre><code>// Create empty struct to test against
  MyInts EmptyStruct = {0};
  
  // Make sure entire memory block of test struct is cleared
  memset(&amp;EmptyStruct, 0, sizeof(MyInts));
  
  // Compare MyStruct to EmptyStruct to see if any non-zero members exist
  int result = memcmp(&amp;MyStruct, &amp;EmptyStruct, sizeof(MyInts));
  </code></pre>