_info 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 my_timer_callback(struct timer *timer)
  29. * {
  30. * struct info *info = container_of(timer, struct info, timer);
  31. * printf("my_stuff is %u\n", info->my_stuff);
  32. * }
  33. *
  34. * int main()
  35. * {
  36. * struct info info = { .my_stuff = 1 };
  37. *
  38. * register_timer(&info.timer);
  39. * // ...
  40. * return 0;
  41. * }
  42. *
  43. * Licence: LGPL (2 or any later version)
  44. * Author: Rusty Russell <rusty@rustcorp.com.au>
  45. */
  46. int main(int argc, char *argv[])
  47. {
  48. if (argc != 2)
  49. return 1;
  50. if (strcmp(argv[1], "depends") == 0) {
  51. printf("ccan/check_type\n");
  52. return 0;
  53. }
  54. return 1;
  55. }