-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.c
More file actions
39 lines (31 loc) · 760 Bytes
/
recursion.c
File metadata and controls
39 lines (31 loc) · 760 Bytes
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
#include <stdio.h>
#include "../tinyhooks.h"
int
fibonacci(int n)
{
if (n == 0 || n == 1)
return n;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
static void
on_fibonacci_enter(tinyhook_enter_context_t *ctx, void *data)
{
fprintf(stderr, "enter\n");
}
static void
on_fibonacci_leave(tinyhook_leave_context_t *ctx, void *data)
{
fprintf(stderr, "leave\n");
}
int
main()
{
tinyhook_t *enter = tinyhook_create_enter(on_fibonacci_enter, NULL);
tinyhook_t *leave = tinyhook_create_leave(on_fibonacci_leave, NULL);
tinyhook_attach(enter, fibonacci);
tinyhook_attach(leave, fibonacci);
fprintf(stdout, "fibonacci(10) = %d\n", fibonacci(10));
tinyhook_destroy(enter);
tinyhook_destroy(leave);
}