Browse Source Download (without any required ccan dependencies)
structeq
bitwise comparison of structs.
Rusty Russell <[email protected]>
This is a replacement for memcmp, which checks the argument types are the same, and takes into account padding in the structure. When there is no padding, it becomes a memcmp at compile time (assuming a constant-optimizing compiler).
#include <ccan/structeq/structeq.h>
#include <ccan/build_assert/build_assert.h>
#include <assert.h>
struct mydata {
int start, end;
};
// Defines mydata_eq(a, b)
STRUCTEQ_DEF(mydata, 0, start, end);
int main(void)
{
struct mydata a, b;
a.start = 100;
a.end = 101;
// They are equal.
assert(mydata_eq(&a, &b));
b.end++;
// Now they are not.
assert(!mydata_eq(&a, &b));
return 0;
}
BSD-MIT