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