OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / 20020402-1.c
1 /* derived from PR c/2100 */
2
3 extern void abort ();
4 extern void exit (int);
5
6 #define SMALL_N  2
7 #define NUM_ELEM 4
8
9 int main(void)
10 {
11   int listElem[NUM_ELEM]={30,2,10,5};
12   int listSmall[SMALL_N];
13   int i, j;
14   int posGreatest=-1, greatest=-1;
15
16   for (i=0; i<SMALL_N; i++) { 
17     listSmall[i] = listElem[i];
18     if (listElem[i] > greatest) {
19       posGreatest = i;
20       greatest = listElem[i];
21     }
22   }
23   
24   for (i=SMALL_N; i<NUM_ELEM; i++) { 
25     if (listElem[i] < greatest) {
26       listSmall[posGreatest] = listElem[i];
27       posGreatest = 0;
28       greatest = listSmall[0];
29       for (j=1; j<SMALL_N; j++) 
30         if (listSmall[j] > greatest) {
31           posGreatest = j;
32           greatest = listSmall[j];
33         }
34     }
35   }
36
37   if (listSmall[0] != 5 || listSmall[1] != 2)
38     abort ();
39   exit (0);
40 }
41