source: src/Clight/test/insertsort.c @ 764

Last change on this file since 764 was 485, checked in by campbell, 10 years ago

Fix treatment of pointers in initialisation data, a little like later versions
of CompCert?. Remove obsolete Init_pointer.

File size: 963 bytes
Line 
1struct list {
2  unsigned char i;
3  __pdata struct list *next;
4};
5
6__pdata struct list l6 = {69, 0};
7__pdata struct list l5 = {36, &l6};
8__pdata struct list l4 = {136, &l5};
9__pdata struct list l3 = {105, &l4};
10__pdata struct list l2 = {234, &l3};
11__pdata struct list l1 = {240, &l2};
12__pdata struct list l0 = {102, &l1};
13
14void insert(__pdata struct list *element, __pdata struct list **dest) {
15  if (*dest == 0 || (*dest)->i >= element->i) {
16    element -> next = *dest;
17    *dest = element;
18  } else
19    insert(element, &(*dest)->next);
20}
21
22void sort(__pdata struct list **list) {
23  __pdata struct list *current;
24  __pdata struct list *next = *list;
25  __pdata struct list *result = 0;
26  while (next) {
27    current = next;
28    next = next->next;
29    insert (current, &result);
30  }
31  *list = result;
32}
33
34extern void out(unsigned char c);
35
36int main(void) {
37  __pdata struct list *l = &l0;
38
39  sort(&l);
40  while (l) {
41    out(l->i);
42    l = l->next;
43  }
44
45  return 0;
46}
Note: See TracBrowser for help on using the repository browser.