]> git.ozlabs.org Git - ccan/blob - ccan/structeq/_info
crypto/shachain/tools: update to new rbuf API.
[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, and takes into account padding in the structure.  When there is no
10  * padding, it becomes a memcmp at compile time (assuming a
11  * constant-optimizing compiler).
12  *
13  * License: BSD-MIT
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  *
16  * Example:
17  *      #include <ccan/structeq/structeq.h>
18  *      #include <ccan/build_assert/build_assert.h>
19  *      #include <assert.h>
20  *      
21  *      struct mydata {
22  *              int start, end;
23  *      };
24  *      // Defines mydata_eq(a, b)
25  *      STRUCTEQ_DEF(mydata, 0, start, end);
26  *      
27  *      int main(void)
28  *      {
29  *              struct mydata a, b;
30  *      
31  *              a.start = 100;
32  *              a.end = 101;
33  *      
34  *              // They are equal.
35  *              assert(mydata_eq(&a, &b));
36  *      
37  *              b.end++;
38  *              // Now they are not.
39  *              assert(!mydata_eq(&a, &b));
40  *      
41  *              return 0;
42  *      }
43  */
44 int main(int argc, char *argv[])
45 {
46         /* Expect exactly one argument */
47         if (argc != 2)
48                 return 1;
49
50         if (strcmp(argv[1], "depends") == 0) {
51                 printf("ccan/build_assert\n");
52                 printf("ccan/cppmagic\n");
53                 return 0;
54         }
55
56         return 1;
57 }