]> git.ozlabs.org Git - ccan/blobdiff - ccan/structeq/_info
ccan/structeq: make it safe when there's padding.
[ccan] / ccan / structeq / _info
index d66e2960c7183b97e3a5934f787890aa4e9fb9e9..1ac8d56ddcbf5e1defa01d86ace0f92f3002e3b3 100644 (file)
@@ -6,9 +6,11 @@
  * structeq - bitwise comparison of structs.
  *
  * This is a replacement for memcmp, which checks the argument types are the
- * same.
+ * 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).
  *
- * License: CC0 (Public domain)
+ * License: BSD-MIT
  * Author: Rusty Russell <rusty@rustcorp.com.au>
  *
  * Example:
  *     struct mydata {
  *             int start, end;
  *     };
+ *     // Defines mydata_eq(a, b)
+ *     STRUCTEQ_DEF(mydata, 0, 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));
+ *             assert(mydata_eq(&a, &b));
  *     
  *             b.end++;
  *             // Now they are not.
- *             assert(!structeq(&a, &b));
+ *             assert(!mydata_eq(&a, &b));
  *     
  *             return 0;
  *     }
@@ -50,6 +48,8 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
+               printf("ccan/build_assert\n");
+               printf("ccan/cppmagic\n");
                return 0;
        }