Browse Source Download (without any required ccan dependencies)

Module:

structeq

Summary:

bitwise comparison of structs.

Author:

Rusty Russell <[email protected]>

Dependencies:

Description:

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).

Example:

#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;
}

License:

BSD-MIT