7h-struct-assign.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 <mes/lib.h>
  21. #include <string.h>
  22. struct string
  23. {
  24. char *str;
  25. int len;
  26. };
  27. typedef struct biggie
  28. {
  29. int a;
  30. int b;
  31. int c;
  32. char *str;
  33. int len;
  34. } biggie;
  35. struct other
  36. {
  37. struct biggie big;
  38. };
  39. struct string g_t;
  40. struct biggie tab[2];
  41. int
  42. main ()
  43. {
  44. struct string s = { "hallo" };
  45. s.len = strlen (s.str);
  46. eputs (s.str);
  47. eputs ("\n");
  48. struct string t;
  49. t = s;
  50. eputs (t.str);
  51. eputs ("\n");
  52. if (t.len != s.len)
  53. return 1;
  54. if (strcmp (t.str, s.str))
  55. return 2;
  56. g_t = s;
  57. eputs (g_t.str);
  58. eputs ("\n");
  59. if (g_t.len != s.len)
  60. return 3;
  61. if (strcmp (g_t.str, s.str))
  62. return 4;
  63. struct biggie b;
  64. b.str = "hello";
  65. b.len = strlen (b.str);
  66. eputs (b.str);
  67. eputs ("\n");
  68. struct biggie tb;
  69. tb = b;
  70. eputs (tb.str);
  71. eputs ("\n");
  72. if (tb.len != b.len)
  73. return 5;
  74. if (strcmp (tb.str, b.str))
  75. return 6;
  76. b.str = "bye";
  77. b.len = strlen (b.str);
  78. eputs (b.str);
  79. eputs ("\n");
  80. //struct biggie *pb = &tb;
  81. biggie *pb = &tb;
  82. *pb = b;
  83. eputs (tb.str);
  84. eputs ("\n");
  85. if (tb.len != b.len)
  86. return 7;
  87. if (strcmp (tb.str, b.str))
  88. return 8;
  89. tb.str = "there";
  90. tb.len = strlen (tb.str);
  91. b = *pb;
  92. eputs (b.str);
  93. eputs ("\n");
  94. if (b.len != tb.len)
  95. return 9;
  96. if (strcmp (b.str, tb.str))
  97. return 10;
  98. char **x = &b.str;
  99. char *p;
  100. p = *x;
  101. struct other o;
  102. struct other *po = &o;
  103. po->big = b;
  104. eputs (o.big.str);
  105. eputs ("\n");
  106. if (o.big.len != b.len)
  107. return 13;
  108. if (strcmp (o.big.str, b.str))
  109. return 14;
  110. po->big = *pb;
  111. eputs (o.big.str);
  112. eputs ("\n");
  113. if (o.big.len != b.len)
  114. return 15;
  115. if (strcmp (o.big.str, b.str))
  116. return 16;
  117. b.str = "* = *";
  118. b.len = strlen (b.str);
  119. eputs (b.str);
  120. eputs ("\n");
  121. struct biggie *q = tab;
  122. pb = &b;
  123. *q++ = *pb;
  124. eputs (tab[0].str);
  125. eputs ("\n");
  126. if (tab[0].len != b.len)
  127. return 17;
  128. if (strcmp (tab[0].str, b.str))
  129. return 18;
  130. tab[1] = tab[0];
  131. eputs (tab[1].str);
  132. eputs ("\n");
  133. if (tab[1].len != b.len)
  134. return 19;
  135. if (strcmp (tab[1].str, b.str))
  136. return 20;
  137. tab[0].str = "burp";
  138. tab[0].len = strlen (tab[1].str);
  139. eputs (tab[0].str);
  140. eputs ("\n");
  141. b = tab[0];
  142. eputs (b.str);
  143. eputs ("\n");
  144. if (b.len != tab[0].len)
  145. return 21;
  146. if (strcmp (b.str, tab[0].str))
  147. return 22;
  148. tab[1] = b;
  149. eputs (tab[1].str);
  150. eputs ("\n");
  151. if (tab[1].len != b.len)
  152. return 23;
  153. if (strcmp (tab[1].str, b.str))
  154. return 24;
  155. return 0;
  156. }