7n-struct-struct-array.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <mes/lib.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. typedef struct file
  26. {
  27. char name[10];
  28. } file_struct;
  29. #define STACK_SIZE 2
  30. struct state
  31. {
  32. int bla;
  33. file_struct *stack[STACK_SIZE];
  34. char buf[100];
  35. file_struct **stack_ptr;
  36. char buf1[100];
  37. };
  38. int
  39. main ()
  40. {
  41. struct state s;
  42. struct state *ps;
  43. ps = &s;
  44. eputs ("0\n");
  45. s.stack_ptr = s.stack;
  46. ps->stack_ptr = ps->stack;
  47. eputs ("ps->stack=");
  48. eputs (itoa (ps->stack));
  49. eputs ("\n");
  50. eputs ("1\n");
  51. if (ps->stack_ptr >= ps->stack + STACK_SIZE)
  52. return 1;
  53. eputs ("2\n");
  54. struct file f = { "first.h" };
  55. #if 0 //__MESC__
  56. strcpy (f.name, "first.h");
  57. #endif
  58. eputs (f.name);
  59. eputs ("\n");
  60. *ps->stack_ptr = &f;
  61. eputs ("3\n");
  62. ++ps->stack_ptr;
  63. eputs ("s.stack_ptr -stack =");
  64. eputs (itoa (ps->stack_ptr - ps->stack));
  65. eputs ("\n");
  66. eputs ("4\n");
  67. for (file_struct ** p = ps->stack; p < ps->stack_ptr; p++)
  68. {
  69. eputs ((*p)->name);
  70. eputs ("\n");
  71. }
  72. eputs ("5\n");
  73. int i;
  74. i = ps->stack_ptr - ps->stack + STACK_SIZE;
  75. eputs ("i=");
  76. eputs (itoa (i));
  77. eputs ("\n");
  78. if (ps->stack_ptr >= ps->stack + STACK_SIZE)
  79. return 2;
  80. eputs ("6\n");
  81. struct file f2 = { "second.h" };
  82. #if 0 //__MESC__
  83. strcpy (f2.name, "second.h");
  84. #endif
  85. *ps->stack_ptr = &f2;
  86. eputs ("7\n");
  87. ++ps->stack_ptr;
  88. eputs ("s.stack_ptr -stack =");
  89. eputs (itoa (ps->stack_ptr - ps->stack));
  90. eputs ("\n");
  91. for (file_struct ** p = ps->stack; p < ps->stack_ptr; p++)
  92. {
  93. eputs ((*p)->name);
  94. eputs ("\n");
  95. }
  96. if (ps->stack_ptr >= ps->stack + STACK_SIZE)
  97. return 0;
  98. struct file f3 = { "third.h" };
  99. *ps->stack_ptr = &f3;
  100. ++ps->stack_ptr;
  101. return 3;
  102. }