Don’t use memcmp to compare structs or classes

Structs and classes can be laid out with padding between the data members for alignment purposes, and this padding doesn’t get initialised unless you specifically zero it out yourself. So if you’re using memcmp and comparing memory at pointers to structs you might have a problem if you’re expecting structs with equal data members to always be equal.

Leave a Reply