blob: 07dfae7ab99fb4f51c0299bf33dc7f40d5982720 (
plain) (
blame)
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
44
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <gc.h>
void *count_solns(void *n);
void *gc_alloc(int size) {
void *p = GC_MALLOC(size);
/*
* To get info about the GC discarding objects, use
* GC_REGISTER_FINALIZER(p, fn, arg, 0, 0);
*
* This runs fn(p, arg) when the object at p is finalised.
*
* More info in gc.h of Boehm garbage collector.
*/
assert(p);
return p;
}
int main(int argc, char **argv) {
/*
* Initialising the GC is not necessary on all systems but may be required
* on some. Better safe than sorry! See gc.h for more info.
*/
GC_INIT();
if (argc != 2) {
printf("usage: %s n\n", argv[0]);
} else {
uintptr_t n = atoi(argv[1]);
int n_solns = (int) count_solns((void *) n);
printf("%i solutions found\n", n_solns);
}
return 0;
}
|