7s-struct-short.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 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. struct foo
  21. {
  22. char c;
  23. short bar;
  24. short baz;
  25. };
  26. struct bar
  27. {
  28. char bar;
  29. };
  30. struct foo global_f = { 0, 11, 22 };
  31. struct bar global_b = { 11 };
  32. int i = 0x11223344;
  33. struct foo foes[2] = { {0, 1, 2}, {0, 3, 4} };
  34. int
  35. main ()
  36. {
  37. if (global_f.bar != 11)
  38. return 1;
  39. if (global_f.baz != 22)
  40. return 2;
  41. struct foo f = { 0, 44, 55 };
  42. if (f.bar != 44)
  43. return 3;
  44. if (f.baz != 55)
  45. return 4;
  46. if (global_b.bar != 11)
  47. return 5;
  48. if (foes[0].bar != 1)
  49. return 6;
  50. if (foes[0].baz != 2)
  51. return foes[0].baz;
  52. if (foes[1].bar != 3)
  53. return 8;
  54. if (foes[1].baz != 4)
  55. return 9;
  56. return 0;
  57. }