1 /* { dg-do compile } */
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <math.h>
6 #include <string.h>
7 
8 void mem_init (void);
9 int ARCHnodes, ARCHnodes1;
10 int ***vel;
11 void just_a_call (int *);
12 
13 /* The last dimension of VEL escapes because it was sent
14    as argument to just_a_call(). (external function)
15    Only the two external dimensions are flattened.
16    Run with -c.  */
17 
18 
19 /*--------------------------------------------------------------------------*/
20 
21 int
main(int argc,char ** argv)22 main (int argc, char **argv)
23 {
24   int i, j, k;
25 
26   ARCHnodes = 2;
27   ARCHnodes1 = 4;
28 
29 /* Dynamic memory allocations and initializations */
30 
31   mem_init ();
32 
33   for (i = 0; i < ARCHnodes; i++)
34     {
35       for (j = 0; j < 3; j++)
36 	{
37 	  for (k = 0; k < ARCHnodes1; k++)
38 	    printf ("[%d][%d][%d]=%d ", i, j, k, vel[i][j][k]);
39 	  printf ("\n");
40 	}
41       printf ("\n");
42     }
43   for (i = 0; i < ARCHnodes; i++)
44     for (j = 0; j < 3; j++)
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 	  fprintf (stderr, "malloc failed for vel[%d]\n", i);
72 	  fflush (stderr);
73 	  exit (0);
74 	}
75     }
76   for (i = 0; i < ARCHnodes; i++)
77     {
78       for (j = 0; j < 3; j++)
79 	{
80 	  vel[i][j] = (int *) malloc (ARCHnodes1 * sizeof (int));
81 	}
82     }
83   for (i = 0; i < ARCHnodes; i++)
84     {
85       for (j = 0; j < 3; j++)
86 	{
87 	  for (k = 0; k < ARCHnodes1; k++)
88 	    {
89 	      vel[i][j][k] = d;
90 	      d++;
91 	    }
92 	}
93     }
94   just_a_call (vel[1][1]);
95 }
96 
97 /*--------------------------------------------------------------------------*/
98