C job interview - casting and comparing

后端 未结 10 891
没有蜡笔的小新
没有蜡笔的小新 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 12:51

    May be he had in mind a definition of MAC that used unsigned char and was thinking to:

    int isEqual(MAC* addr1, MAC* addr2) { return strncmp((*addr1).data,(*addr2).data,6)==0; }

    which implies a cast from (unsigned char *) to (char *). Anyway bad question.

提交回复
热议问题