commit 88953dff6192486aeb136c1cfabc4abc7c350bea
parent c16d21c43716c22ff6777dbccde5fbdfd8d67dd2
Author: Samdal <samdal@protonmail.com>
Date: Sat, 22 Feb 2025 09:32:15 +0100
fix typos
Diffstat:
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/_posts/2025-02-22-making-generic-data-structures-in-C.md b/_posts/2025-02-22-making-generic-data-structures-in-C.md
@@ -9,15 +9,15 @@ tags: [writing, programming, C]
Static typing is amazing, it reduces a lot of bugs. However, having too many types hinders the uniformity of your code.
-Modern languages have tooling to reduce the amount of work you have to do when your code base has a lot of similar types.
-Although I don't always agree that creating and working with these types is a good idea, I do use generics in C as well.
+Modern languages have tooling to automatically do generic types, C does not.
+I don't always agree that creating and using generics is a good idea, but I do use generics in C as well.
## How it's normally done in C
-Usually C programmers just use `void*` and then (hopefully) wrap functoins around the operations.
-This has many issues, mainly that it is hard to work with, and has no type safety.
+Usually C programmers just use `void*` and then wrap functoins around the operations.
+This has many issues, mainly that it is hard to work with. It also has no type safety.
-> Note that in cases where you don't need type safety or easy top-level operations, `void*` is an excellent tool.
+> Note that in cases where you don't need type safety or easy top-level operations, `void*` may be an excellent tool.
Example of a `void*` based linked list:
@@ -105,7 +105,7 @@ typedef struct {
#define dyn_arr_get_sz(arr) (((_dyn_arr_header*)((u8*)(arr) - sizeof(_dyn_arr_header)))->sz)
#define dyn_arr_push(arr, new_val) ( \
- arr = realloc(sizeof(_dyn_arr_header) + (dyn_arr_get_sz(arr) + 1) * sizeof(*(arr))), \
+ arr = realloc(arr, sizeof(_dyn_arr_header) + (dyn_arr_get_sz(arr) + 1) * sizeof(*arr)), \
arr[dyn_arr_get_sz(arr)-1] = new_val \
)
```
@@ -118,7 +118,7 @@ dyn_arr_push(my_arr, 20.0f);
assert(my_arr[1] == 20.0f);;
```
I don't really use dynamic arrays anymore, and that's mostly where this technique is useful.
-
+This technique creates more obfuscated and harder to use code than if your types are exposed.
## Going a bit crazy