79-int-array.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,2018 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 <stdio.h>
  22. #include <string.h>
  23. struct foo
  24. {
  25. int *bar;
  26. };
  27. struct foo f;
  28. int bla[6] = { 0, 0, 11223344, 55667788, 0, 0 };
  29. int g_c[2] = { 101, 111 };
  30. int
  31. main ()
  32. {
  33. f.bar = bla;
  34. struct foo *pf = &f;
  35. int *b = pf->bar;
  36. if (bla[2] != 11223344)
  37. return 1;
  38. if (bla[3] != 55667788)
  39. return 2;
  40. if (b[2] != 11223344)
  41. return 3;
  42. if (b[3] != 55667788)
  43. return 4;
  44. eputs ("g_c[0]=");
  45. eputs (itoa (g_c[0]));
  46. eputs ("\n");
  47. eputs ("g_c[1]=");
  48. eputs (itoa (g_c[1]));
  49. eputs ("\n");
  50. memcpy (&b[2], g_c, 2 * sizeof (int));
  51. eputs ("b[2]:");
  52. eputs (itoa (b[2]));
  53. eputs ("\n");
  54. if (b[2] != 101)
  55. return 5;
  56. eputs ("b[3]:");
  57. eputs (itoa (b[3]));
  58. eputs ("\n");
  59. if (b[3] != 111)
  60. return 6;
  61. int c[2] = { 201, 211 };
  62. eputs ("c[0]=");
  63. eputs (itoa (c[0]));
  64. eputs ("\n");
  65. eputs ("c[1]=");
  66. eputs (itoa (c[1]));
  67. eputs ("\n");
  68. memcpy (&b[4], c, 2 * sizeof (int));
  69. eputs ("b[4]:");
  70. eputs (itoa (b[4]));
  71. eputs ("\n");
  72. if (b[4] != 201)
  73. return 7;
  74. eputs ("b[5]:");
  75. eputs (itoa (b[5]));
  76. eputs ("\n");
  77. if (b[5] != 211)
  78. return 8;
  79. return 0;
  80. }