aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/init.c
blob: 24d1b7f0598322bf28ab8b13a624afe81a873df1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
int gexplicit[4] = { 7, 3, 4, 5, };
_Static_assert(sizeof gexplicit/sizeof *gexplicit ==4, "");
int gimplicit[] = { 3, 5, };
_Static_assert(sizeof gimplicit/sizeof *gimplicit ==2, "");
char dim2[][2] = { {1,2},4,3 };
_Static_assert(sizeof dim2 == 4, "dim2");
struct S{int x; int a[2][12];} S = {1,{{0,3},2}};

const union U {int x; int y[2];} U = {1,};

char str[] = "abcdef";
_Static_assert(sizeof str == 7, "str[7]");

const char strs[][2] = {"ax", {'c','x'}, 'd',"?x"[1], "bx"};

/*
struct { int y; signed char x[]; } flex1  = {0, {0}};
struct { int y; signed char x[]; } flex2  = {0, 1,4,5};
struct { int y; signed char x[]; } flex3  = {0, "/"};
*/

struct  { float x, y; } desgn1[] = {[1]=1.f,3, -0.5};
_Static_assert(sizeof desgn1/sizeof *desgn1 == 3,"");

struct n { void * j; struct { int y; float z; }; void *g;} desgn2 = { .y = 0, 1.0f, 0, 8 };
struct n2 { void * j; struct as { struct { int y; }; float z; } a[3]; char *g;} desgn3 = { .a={-1}, .a[2].y = 6, 1.0f, "k" };

char *s = "abc";
const char *ss[] = {"red","blue","green"};

union fi {float f; int i;} fi = {.i = 0xFF<<22,};

char arrdsgn[] = { [4] = 1, [1] = 5 };
_Static_assert(sizeof arrdsgn == 5, "");

// int q[1] = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{1}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}};

/*
void f() {
   struct {int x,y;} a = {1,2}, b = {3,4}, c[] = {a,b};
}
*/

void *rec[1] = {rec};

int printf(char *, ...);
int main() {
   printf("gexplicit[4] \t%d,%d,%d,%d\n", gexplicit[0], gexplicit[1], gexplicit[2], gexplicit[3]);
   printf("gimplicit[] \t%d,%d\n", gimplicit[0], gimplicit[1]);
   printf("dim2[2][2] \t{%d,%d}, {%d,%d}\n", dim2[0][0],dim2[0][1],dim2[1][0],dim2[1][1]);
   printf("S.x = %d, S.a[0][1] = %d, S.a[1][0] = %d\n", S.x, S.a[0][1], S.a[1][0]);
   printf("U.x = %d\n", U.x);
   printf("str[] \t\"%s\"\n", str);
   printf("strs \t\"%.*s\"\n", (int)sizeof strs, strs);
   printf("desgn1[] \t{%f,%f}, {%f,%f}, {%f,%f}\n", desgn1[0].x, desgn1[0].y, desgn1[1].x, desgn1[1].y, desgn1[2].x, desgn1[2].y);
   printf("desgn2 \t{%p,{%d,%f},%s}\n", desgn2.j, desgn2.y, desgn2.z, desgn2.g);
   printf("desgn3 \t{%p,{{{%d},%f},{{%d},%f},{{%d},%f}},\"%s\"}\n", desgn3.j,
         desgn3.a[0].y, desgn3.a[0].z, desgn3.a[1].y, desgn3.a[1].z,
         desgn3.a[2].y, desgn3.a[2].z, desgn3.g);
   printf("fi \t{%f | %d}\n", fi.f, fi.i);
   printf("arrdsgn[] \t{%d,%d,%d,%d,%d}\n", arrdsgn[0], arrdsgn[1], arrdsgn[2], arrdsgn[3], arrdsgn[4]);
   printf("s \t\"%s\"\n", s);
   printf("ss[] \t{\"%s\",\"%s\",\"%s\"}\n", ss[0],ss[1],ss[2]);
   printf("rec \t%p{%p}\n",rec,rec[0]);
}