Also, is it that much harder to do this (C++ for example):
struct S {
char c = 0;
int i = 0;
bool operator==(const S &other) const {
return c == other.c && i == other.i;
}
};
S a, b;
if(something) return !(a == b);
return 3;
Bam, no undefined behavior and you don't have to remember to manually zero out the structure everywhere.
If you're using memcmp on an object, you should be asserting that std::has_unique_object_representations<T> is true for it (unfortunately this is only available after C++17).
Also, if you are okay with anonymous field names:
std::tuple<char, int> a, b;
if(something) return a != b;
return 3;
Also, is it that much harder to do this (C++ for example):
Bam, no undefined behavior and you don't have to remember to manually zero out the structure everywhere.If you're using memcmp on an object, you should be asserting that std::has_unique_object_representations<T> is true for it (unfortunately this is only available after C++17).
Also, if you are okay with anonymous field names: