_info 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * container_of - routine for upcasting
  6. *
  7. * It is often convenient to create code where the caller registers a pointer
  8. * to a generic structure and a callback. The callback might know that the
  9. * pointer points to within a larger structure, and container_of gives a
  10. * convenient and fairly type-safe way of returning to the enclosing structure.
  11. *
  12. * This idiom is an alternative to providing a void * pointer for every
  13. * callback.
  14. *
  15. * Example:
  16. * #include <stdio.h>
  17. * #include <ccan/container_of/container_of.h>
  18. *
  19. * struct timer {
  20. * void *members;
  21. * };
  22. *
  23. * struct info {
  24. * int my_stuff;
  25. * struct timer timer;
  26. * };
  27. *
  28. * static void register_timer(struct timer *timer)
  29. * {
  30. * //...
  31. * }
  32. *
  33. * static void my_timer_callback(struct timer *timer)
  34. * {
  35. * struct info *info = container_of(timer, struct info, timer);
  36. * printf("my_stuff is %u\n", info->my_stuff);
  37. * }
  38. *
  39. * int main(void)
  40. * {
  41. * struct info info = { .my_stuff = 1 };
  42. *
  43. * register_timer(&info.timer);
  44. * // ...
  45. * return 0;
  46. * }
  47. *
  48. * License: LGPL (2 or any later version)
  49. * Author: Rusty Russell <rusty@rustcorp.com.au>
  50. */
  51. int main(int argc, char *argv[])
  52. {
  53. if (argc != 2)
  54. return 1;
  55. if (strcmp(argv[1], "depends") == 0) {
  56. printf("ccan/check_type\n");
  57. return 0;
  58. }
  59. return 1;
  60. }