title: C job interview - casting and comparing
body: <p>I was confronted with a tricky (IMO) question. I needed to compare two <a href="http://en.wikipedia.org/wiki/MAC_address" rel="noreferrer">MAC addresses</a>, in the most efficient manner.</p>
  
  <p>The only thought that crossed my mind in that moment was the trivial solution - a <code>for</code> loop, and comparing locations, and so I did, but the interviewer was aiming to casting.</p>
  
  <p>The MAC definition:</p>
  
  <pre><code>typedef struct macA {
     char data[6];
  } MAC;
  </code></pre>
  
  <p>And the function is (the one I was asked to implement):</p>
  
  <pre><code>int isEqual(MAC* addr1, MAC* addr2)
  {
      int i;
  
      for(i = 0; i&lt;6; i++)
      {
          if(addr1-&gt;data[i] != addr2-&gt;data[i]) 
              return 0;
      }
      return 1;
  }
  </code></pre>
  
  <p>But as mentioned, he was aiming for casting.</p>
  
  <p>Meaning, to somehow cast the MAC address given to an int, compare both of the addresses, and return.</p>
  
  <p>But when casting, <code>int int_addr1 = (int)addr1;</code>, only four bytes will be casted, right? Should I check the remaining ones? Meaning locations 4 and 5?</p>
  
  <p>Both <code>char</code> and <code>int</code> are integer types so casting is legal, but what happens 
  in the described situation?</p>