diff options
| author | Tom Harley | 2020-01-08 14:14:39 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-08 14:14:39 +0000 |
| commit | 4cdc57ce8041aecabd3175f2dff176b115f17724 (patch) | |
| tree | da9a25e2d18ce5f4415d4c61441962e9e06ee727 /examples/nq/glue.c | |
| parent | checkpoint (diff) | |
| download | sinter-4cdc57ce8041aecabd3175f2dff176b115f17724.tar.gz sinter-4cdc57ce8041aecabd3175f2dff176b115f17724.zip | |
I should commit more
Diffstat (limited to 'examples/nq/glue.c')
| -rw-r--r-- | examples/nq/glue.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/nq/glue.c b/examples/nq/glue.c new file mode 100644 index 0000000..5d8c6f0 --- /dev/null +++ b/examples/nq/glue.c @@ -0,0 +1,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 { + int n = atoi(argv[1]); + int n_solns = *((int *) count_solns(&n)); + printf("%i solutions found\n", n_solns); + + } + + return 0; +} |
