Browse Source Download (without any required ccan dependencies)

Module:

structeq

Summary:

bitwise comparison of structs.

Author:

Rusty Russell <rusty@rustcorp.com.au>

Description:

This is a replacement for memcmp, which checks the argument types are the same.

Example:

#include <ccan/structeq/structeq.h>
#include <ccan/build_assert/build_assert.h>
#include <assert.h>

struct mydata {
        int start, end;
};

int main(void)
{
        struct mydata a, b;

        // No padding in struct, otherwise this doesn't work!
        BUILD_ASSERT(sizeof(a) == sizeof(a.start) + sizeof(a.end));

        a.start = 100;
        a.end = 101;

        b.start = 100;
        b.end = 101;

        // They are equal.
        assert(structeq(&a, &b));

        b.end++;
        // Now they are not.
        assert(!structeq(&a, &b));

        return 0;
}

License:

CC0 (Public domain)