77-pointer-assign.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <string.h>
  21. #include <mes/lib.h>
  22. struct baz
  23. {
  24. int i;
  25. int j;
  26. };
  27. struct foo
  28. {
  29. int **bar;
  30. };
  31. void
  32. add0 (void *ptab)
  33. {
  34. void **pp = *(void ***) ptab;
  35. bla:
  36. pp[0] = 0x11223344;
  37. }
  38. void
  39. add1 (void *ptab)
  40. {
  41. void ***x = (void ***) ptab;
  42. bla:
  43. *(void ***) ptab = 0x22334455;
  44. }
  45. void
  46. add2 (void *ptab)
  47. {
  48. void ***x = (void ***) ptab;
  49. bla:
  50. *x = 0x33445566;
  51. }
  52. struct foo *hash_ident[10];
  53. int
  54. main ()
  55. {
  56. int i = 1;
  57. int *p = &i;
  58. struct foo f;
  59. f.bar = &p;
  60. eputs ("f.bar:");
  61. eputs (itoa (f.bar));
  62. eputs ("\n");
  63. add0 (&f.bar);
  64. eputs ("f.bar:");
  65. eputs (itoa (*f.bar));
  66. eputs ("\n");
  67. if (*f.bar != 0x11223344)
  68. return 1;
  69. add1 (&f.bar);
  70. eputs ("f.bar:");
  71. eputs (itoa (f.bar));
  72. eputs ("\n");
  73. if (f.bar != 0x22334455)
  74. return 2;
  75. add2 (&f.bar);
  76. eputs ("f.bar:");
  77. eputs (itoa (f.bar));
  78. eputs ("\n");
  79. if (f.bar != 0x33445566)
  80. return 3;
  81. hash_ident[0] = 10;
  82. *hash_ident = 0;
  83. memset (hash_ident, 0, 10);
  84. struct baz b;
  85. b.i = b.j = 1;
  86. if (b.i != 1)
  87. return 4;
  88. struct baz *pb = &b;
  89. pb->i = pb->j = 1;
  90. if (pb->i != 1)
  91. return 5;
  92. return 0;
  93. }