1/*
2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7struct foo { int x, y; };
8
9struct bar { struct foo f; char c[3]; int a[6]; };
10
11int simple1(void)
12{
13  struct foo s = {1,2};
14  return s.x;
15}
16
17int simple2(void)
18{
19  struct foo s = {.y = 2};
20  return s.x;
21}
22
23int simple3(void)
24{
25  int array[10] = {1,2,3};
26  return array[1];
27}
28
29int simple4(void)
30{
31  int array[10] = {[1] = 4, [6] = 7,};
32  return array[6];
33}
34
35int simple5(void)
36{
37  char carr[5] = {1};
38}
39
40struct bar f(int i)
41{
42  return (struct bar){.f = {.y = i, .x = i+1,}, .c = {1,[2] = 2}};
43}
44
45int g(int j)
46{
47  struct bar b = {1,2,3,4,5};
48  return b.c[1]; // should be 4
49}
50
51int h(void)
52{
53  int array[10] = {[4] = 10,[5] = 10};
54  return array[0]; // returns 0
55}
56
57int function(void)
58{
59  struct foo record = {.x = 3,};
60  return record.x;
61}
62
63int function2(void)
64{
65  struct bar b = { .f.x = 3, 1,2 };
66  return b.f.x; // returns 3
67}
68
69int function3(void)
70{
71  int a[5] = {1,2,3,4,5,[1] = 10};
72  return a[1];
73}
74
75int main(int argc, char**argv)
76{
77  struct foo f = {10,12};
78  struct bar test = {f,{1,2},{101}}, test2 = {{1}, {2}, {3}};
79  struct bar b_array[10] = { test, test2, 1, 2 };
80  int aa[] = {1,2,3,[10] = 6};
81  return b_array[2].f.x + b_array[0].c[2] + b_array[1].c[0]; // returns 3
82}
83
84struct sjwbar {
85  int words[1];
86};
87typedef struct sjwbar bar_t;
88
89int sjw(int sj_w)
90{
91  bar_t w = { .words = {sj_w} };
92}
93
94enum anenum { val1, val2 = -1 };
95
96struct inc_enum {
97  enum anenum e;
98  int x;
99};
100
101int enum_test(int x)
102{
103  struct inc_enum s = { .x = 3 }, t = { .e = val2 };
104  return t.e;
105}
106