struct.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include<stdlib.h>
  18. #include<stdio.h>
  19. #include "gcc_req.h"
  20. struct foo
  21. {
  22. struct foo* next;
  23. struct foo* prev;
  24. FUNCTION* run;
  25. int a;
  26. int b;
  27. };
  28. void print_hex(int a, int count, FUNCTION foo2)
  29. {
  30. if(count <= 0) return;
  31. print_hex(a >> 4, count - 1, foo2);
  32. foo2((a & 15) + 48);
  33. }
  34. int main()
  35. {
  36. struct foo* a = malloc(sizeof(struct foo));
  37. struct foo* b = malloc(sizeof(struct foo));
  38. a->run = putchar;
  39. a->a = 0x35419896;
  40. a->b = 0x57891634;
  41. b->a = 0x13579246;
  42. b->b = 0x64297531;
  43. a->next = b;
  44. a->prev = b;
  45. b->next = a;
  46. b->prev = a;
  47. print_hex(a->next->next->a, 8, a->run);
  48. print_hex(b->prev->prev->b, 8, putchar);
  49. print_hex(b->next->a, 8, putchar);
  50. print_hex(b->prev->b, 8, putchar);
  51. putchar(10);
  52. return sizeof(struct foo);
  53. }