]> git.ozlabs.org Git - ccan/blob - ccan/structeq/_info
structeq: new module.
[ccan] / ccan / structeq / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * structeq - bitwise comparison of structs.
7  *
8  * This is a replacement for memcmp, which checks the argument types are the
9  * same.
10  *
11  * License: CC0 (Public domain)
12  * Author: Rusty Russell <rusty@rustcorp.com.au>
13  *
14  * Example:
15  *      #include <ccan/structeq/structeq.h>
16  *      #include <ccan/build_assert/build_assert.h>
17  *      #include <assert.h>
18  *      
19  *      struct mydata {
20  *              int start, end;
21  *      };
22  *      
23  *      int main(void)
24  *      {
25  *              struct mydata a, b;
26  *      
27  *              // No padding in struct, otherwise this doesn't work!
28  *              BUILD_ASSERT(sizeof(a) == sizeof(a.start) + sizeof(a.end));
29  *      
30  *              a.start = 100;
31  *              a.end = 101;
32  *      
33  *              b.start = 100;
34  *              b.end = 101;
35  *      
36  *              // They are equal.
37  *              assert(structeq(&a, &b));
38  *      
39  *              b.end++;
40  *              // Now they are not.
41  *              assert(!structeq(&a, &b));
42  *      
43  *              return 0;
44  *      }
45  */
46 int main(int argc, char *argv[])
47 {
48         /* Expect exactly one argument */
49         if (argc != 2)
50                 return 1;
51
52         if (strcmp(argv[1], "depends") == 0) {
53                 return 0;
54         }
55
56         return 1;
57 }