Should I use memcmp or chained equal-to operations when both give the same result?
Precondition : Consider such a class or struct T , that for two objects a and b of type T memcmp(&a, &b, sizeof(T)) == 0 yields the same result as a.member1 == b.member1 && a.member2 == b.member2 && ... ( memberN is a non-static member variable of T ). Question : When should memcmp be used to compare a and b for equality, and when should the chained == s be used? Here's a simple example: struct vector { int x, y; }; To overload operator == for vector , there are two possibilities (if they're guaranteed to give the same result): bool operator==(vector lhs, vector rhs) { return lhs.x == rhs.x &&