OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [testsuite/] [gcc.dg/] [gnu89-init-1.c] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Test for GNU extensions to compound literals */
2
/* Origin: Jakub Jelinek <jakub@redhat.com> */
3
/* { dg-do run } */
4
/* { dg-options "-std=gnu89" } */
5
 
6
extern void abort (void);
7
extern void exit (int);
8
 
9
struct A { int i; int j; int k[4]; };
10
struct B { };
11
struct C { int i; };
12
struct D { int i; struct C j; };
13
 
14
/* As a GNU extension, we allow initialization of objects with static storage
15
   duration by compound literals.  It is handled as if the object
16
   was initialized only with the bracket enclosed list if compound literal's
17
   and object types match.  If the object being initialized has array type
18
   of unknown size, the size is determined by compound literal's initializer
19
   list, not by size of the compound literal.  */
20
 
21
struct A a = (struct A) { .j = 6, .k[2] = 12 };
22
struct B b = (struct B) { };
23
int c[] = (int []) { [2] = 6, 7, 8 };
24
int d[] = (int [3]) { 1 };
25
int e[2] = (int []) { 1, 2 };
26
int f[2] = (int [2]) { 1 };
27
struct C g[3] = { [2] = (struct C) { 13 }, [1] = (const struct C) { 12 } };
28
struct D h = { .j = (struct C) { 15 }, .i = 14 };
29
struct D i[2] = { [1].j = (const struct C) { 17 },
30
                  [0] = { 0, (struct C) { 16 } } };
31
struct C j[2][3] = { [0 ... 1] = { [0 ... 2] = (struct C) { 26 } } };
32
struct C k[3][2] = { [0 ... 2][0 ... 1] = (const struct C) { 27 } };
33
 
34
int main (void)
35
{
36
  if (a.i || a.j != 6 || a.k[0] || a.k[1] || a.k[2] != 12 || a.k[3])
37
    abort ();
38
  if (c[0] || c[1] || c[2] != 6 || c[3] != 7 || c[4] != 8)
39
    abort ();
40
  if (sizeof (c) != 5 * sizeof (int))
41
    abort ();
42
  if (d[0] != 1 || d[1] || d[2])
43
    abort ();
44
  if (sizeof (d) != 3 * sizeof (int))
45
    abort ();
46
  if (e[0] != 1 || e[1] != 2)
47
    abort ();
48
  if (sizeof (e) != 2 * sizeof (int))
49
    abort ();
50
  if (f[0] != 1 || f[1])
51
    abort ();
52
  if (sizeof (f) != 2 * sizeof (int))
53
    abort ();
54
  if (g[0].i || g[1].i != 12 || g[2].i != 13)
55
    abort ();
56
  if (h.i != 14 || h.j.i != 15)
57
    abort ();
58
  if (i[0].i || i[0].j.i != 16 || i[1].i || i[1].j.i != 17)
59
    abort ();
60
  if (j[0][0].i != 26 || j[0][1].i != 26 || j[0][2].i != 26)
61
    abort ();
62
  if (j[1][0].i != 26 || j[1][1].i != 26 || j[1][2].i != 26)
63
    abort ();
64
  if (k[0][0].i != 27 || k[0][1].i != 27 || k[1][0].i != 27)
65
    abort ();
66
  if (k[1][1].i != 27 || k[2][0].i != 27 || k[2][1].i != 27)
67
    abort ();
68
  exit (0);
69
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.