Skip to content

Commit 30ec4e6

Browse files
committed
Update home page
1 parent 19cb91a commit 30ec4e6

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

content/index.mdx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { Heart, Star, User } from 'lucide-react';
99

1010
A colorful, lightweight error-propagation framework for C.
1111

12-
[Get Started →](/docs)
12+
* [Source Code](https://github.com/c-modules/c_traceback)
13+
* [Get Started →](/docs)
14+
15+
<img src={"/images/general/compilation_info.png"} alt="C Traceback" />
1316

1417
## Features
1518
* Beautiful tracebacks
@@ -20,6 +23,56 @@ A colorful, lightweight error-propagation framework for C.
2023
* Written in C99 with minimal dependencies
2124
* Detailed documentations
2225

26+
## Sample usage
27+
```c
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include "c_traceback.h"
31+
32+
#define N 100
33+
34+
static void do_calculation(double *vec);
35+
36+
int main(void)
37+
{
38+
ctb_clear_context();
39+
ctb_install_signal_handler();
40+
41+
double *vec = malloc(N * sizeof(double));
42+
if (!vec)
43+
{
44+
THROW(CTB_MEMORY_ERROR, "Failed to allocate memory");
45+
goto error;
46+
}
47+
48+
TRY_GOTO(do_calculation(vec), error);
49+
printf("This shouldn't be printed if there is error\n");
50+
51+
free(vec);
52+
return 0;
53+
54+
error:
55+
free(vec);
56+
ctb_dump_traceback(); // Log traceback and reset context
57+
return 0;
58+
}
59+
60+
static void do_calculation(double *vec)
61+
{
62+
// Initialize array
63+
for (int i = 0; i < N; i++)
64+
{
65+
vec[i] = 0;
66+
}
67+
68+
// Calculations
69+
for (int i = 0; i < N; i++)
70+
{
71+
vec[i] += 10;
72+
}
73+
}
74+
```
75+
2376
## Support Us
2477
{/* * <Heart size="1.1em" className="inline fill-red-400 stroke-red-400" /> [Sponsor](https://github.com/c-modules/c_traceback) */}
2578
* <Star size="1.1em" className="inline fill-yellow-400 stroke-yellow-400" /> [Give us a star on GitHub](https://github.com/c-modules/c_traceback)
598 KB
Loading

0 commit comments

Comments
 (0)