C job interview - casting and comparing

后端 未结 10 730
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 12:29

I was confronted with a tricky (IMO) question. I needed to compare two MAC addresses, in the most efficient manner.

The only thought that crossed my mind in that moment

10条回答
  •  遇见更好的自我
    2021-02-01 13:00

    If he is really dissatisfied with this approach (which is essentially a brain fart, since you aren't comparing megabytes or gigabytes of data, so one shan't really be worrying about "efficiency" and "speed" in this case), just tell him that you trust the quality and speed of the standard library:

    int isEqual(MAC* addr1, MAC* addr2)
    {
        return memcmp(&addr1->data, &addr2->data, sizeof(addr1->data)) == 0;
    }
    

提交回复
热议问题