struct.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. struct foo
  20. {
  21. struct foo* next;
  22. struct foo* prev;
  23. int a;
  24. int b;
  25. };
  26. void print_hex(int a, int count)
  27. {
  28. if(count <= 0) return;
  29. print_hex(a >> 4, count - 1);
  30. putchar((a & 15) + 48);
  31. }
  32. int main()
  33. {
  34. struct foo* a = malloc(sizeof(struct foo));
  35. struct foo* b = malloc(sizeof(struct foo));
  36. a->a = 0x35419896;
  37. a->b = 0x57891634;
  38. b->a = 0x13579246;
  39. b->b = 0x64297531;
  40. a->next = b;
  41. a->prev = b;
  42. b->next = a;
  43. b->prev = a;
  44. print_hex(a->next->next->a, 8);
  45. print_hex(b->prev->prev->b, 8);
  46. print_hex(b->next->a, 8);
  47. print_hex(b->prev->b, 8);
  48. putchar(10);
  49. return sizeof(struct foo);
  50. }