]>
Commit | Line | Data |
---|---|---|
207b66ce UD |
1 | /* Test case by Paul Eggert <eggert@twinsun.com> */ |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | ||
5 | struct big { char c[4 * 1024]; }; | |
6 | ||
7 | struct big *array; | |
8 | struct big *array_end; | |
9 | ||
10 | int | |
11 | compare (void const *a1, void const *b1) | |
12 | { | |
13 | struct big const *a = a1; | |
14 | struct big const *b = b1; | |
15 | if (! (array <= a && a < array_end | |
16 | && array <= b && b < array_end)) | |
17 | { | |
18 | exit (EXIT_FAILURE); | |
19 | } | |
20 | return b->c[0] - a->c[0]; | |
21 | } | |
22 | ||
23 | int | |
24 | main (int argc, char **argv) | |
25 | { | |
26 | size_t i; | |
27 | size_t array_members = argv[1] ? atoi (argv[1]) : 50; | |
28 | array = (struct big *) malloc (array_members * sizeof *array); | |
29 | if (array == NULL) | |
30 | { | |
31 | puts ("no memory"); | |
32 | exit (EXIT_FAILURE); | |
33 | } | |
34 | ||
35 | array_end = array + array_members; | |
36 | for (i = 0; i < array_members; i++) | |
37 | array[i].c[0] = i % 128; | |
38 | ||
39 | qsort (array, array_members, sizeof *array, compare); | |
40 | ||
41 | return 0; | |
42 | } |