_info.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * struct info
  17. * {
  18. * int my_stuff;
  19. * struct timer timer;
  20. * };
  21. *
  22. * static void my_timer_callback(struct timer *timer)
  23. * {
  24. * struct info *info = container_of(timer, struct info, timer);
  25. * printf("my_stuff is %u\n", info->my_stuff);
  26. * }
  27. *
  28. * int main()
  29. * {
  30. * struct info info = { .my_stuff = 1 };
  31. *
  32. * register_timer(&info.timer);
  33. * ...
  34. */
  35. int main(int argc, char *argv[])
  36. {
  37. if (argc != 2)
  38. return 1;
  39. if (strcmp(argv[1], "depends") == 0) {
  40. printf("check_type\n");
  41. return 0;
  42. }
  43. return 1;
  44. }