_info 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * build_assert - routines for build-time assertions
  6. *
  7. * This code provides routines which will cause compilation to fail should some
  8. * assertion be untrue: such failures are preferable to run-time assertions,
  9. * but much more limited since they can only depends on compile-time constants.
  10. *
  11. * These assertions are most useful when two parts of the code must be kept in
  12. * sync: it is better to avoid such cases if possible, but seconds best is to
  13. * detect invalid changes at build time.
  14. *
  15. * For example, a tricky piece of code might rely on a certain element being at
  16. * the start of the structure. To ensure that future changes don't break it,
  17. * you would catch such changes in your code like so:
  18. *
  19. * Example:
  20. * #include <stddef.h>
  21. * #include <ccan/build_assert/build_assert.h>
  22. *
  23. * struct foo {
  24. * char string[5];
  25. * int x;
  26. * };
  27. *
  28. * static char *foo_string(struct foo *foo)
  29. * {
  30. * // This trick requires that the string be first in the structure
  31. * BUILD_ASSERT(offsetof(struct foo, string) == 0);
  32. * return (char *)foo;
  33. * }
  34. *
  35. * License: Public domain
  36. * Author: Rusty Russell <rusty@rustcorp.com.au>
  37. */
  38. int main(int argc, char *argv[])
  39. {
  40. if (argc != 2)
  41. return 1;
  42. if (strcmp(argv[1], "depends") == 0)
  43. /* Nothing. */
  44. return 0;
  45. return 1;
  46. }