1 /* { dg-do run } */
2 /* { dg-options "-fwhole-program" } */
3
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <string.h>
9
10 void mem_init (void);
11 int ARCHnodes, ARCHnodes1;
12 int ***vel;
13
14 /* The last dimension of VEL escapes because of
15 the assignment : *vel[1] =...
16 Only the two external dimensions are flattened. */
17
18 /*--------------------------------------------------------------------------*/
19
20 int
main(int argc,char ** argv)21 main (int argc, char **argv)
22 {
23 int i, j, k;
24
25 ARCHnodes = 2;
26 ARCHnodes1 = 4;
27
28 /* Dynamic memory allocations and initializations */
29
30 mem_init ();
31
32 for (i = 0; i < ARCHnodes; i++)
33 {
34 for (j = 0; j < 3; j++)
35 {
36 for (k = 0; k < ARCHnodes1; k++)
37 printf ("[%d][%d][%d]=%d ", i, j, k, vel[i][j][k]);
38 printf ("\n");
39 }
40 printf ("\n");
41 }
42 for (i = 0; i < ARCHnodes; i++)
43 for (j = 0; j < 3; j++)
44 if (!(i == 1 && j == 0))
45 free (vel[i][j]);
46
47 for (i = 0; i < ARCHnodes; i++)
48 free (vel[i]);
49
50 free (vel);
51 return 0;
52 }
53
54 /*--------------------------------------------------------------------------*/
55 /* Dynamic memory allocations and initializations */
56
57 void
mem_init(void)58 mem_init (void)
59 {
60
61 int i, j, k,d;
62
63 d = 0;
64 vel = (int ***) malloc (ARCHnodes * sizeof (int **));
65
66 for (i = 0; i < ARCHnodes; i++)
67 {
68 vel[i] = (int **) malloc (3 * sizeof (int *));
69 if (vel[i] == (int **) NULL)
70 {
71 printf ("malloc failed for vel[%d]\n", i);
72 exit (0);
73 }
74 }
75 for (i = 0; i < ARCHnodes; i++)
76 {
77 for (j = 0; j < 3; j++)
78 {
79 vel[i][j] = (int *) malloc (ARCHnodes1 * sizeof (int));
80 }
81 }
82 for (i = 0; i < ARCHnodes; i++)
83 {
84 for (j = 0; j < 3; j++)
85 {
86 for (k = 0; k < ARCHnodes1; k++)
87 {
88 vel[i][j][k] = d;
89 d++;
90 }
91 }
92 }
93 *vel[1] = &d;
94 }
95
96 /*--------------------------------------------------------------------------*/
97