File: cons.c

package info (click to toggle)
mlton 20041109-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,212 kB
  • ctags: 58,085
  • sloc: ansic: 10,386; makefile: 1,178; sh: 1,139; pascal: 256; asm: 97
file content (43 lines) | stat: -rw-r--r-- 721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>

typedef unsigned int uint;

typedef struct Cons {
	struct Cons *next;
	int value;
} *Cons;

Cons listCons (int n, Cons c) {
	Cons res;

	res = (Cons) malloc (sizeof(*res));
	fprintf (stderr, "0x%08x = listCons (%d)\n", (uint)res, n);
	res->next = c;
	res->value = n;
	return res;
}

Cons listSing (int n) {
	Cons res;

	res = (Cons) malloc (sizeof(*res));
	fprintf (stderr, "0x%08x = listSing (%d)\n", (uint)res, n);
	res->next = NULL;
	res->value = n;
	return res;
}

void listFree (Cons p) {
	fprintf (stderr, "listFree (0x%08x)\n", (uint)p);
	free (p);
}

int listSum (Cons c) {
	int res;

	fprintf (stderr, "listSum\n");
	res = 0;
	for (; c != NULL; c = c->next)
		res += c->value;
	return res;
}