pretty sure C is the new Go.
I write type-safe generic data structures in C
21–30 of 196 posts
Re: I write type-safe generic data structures in C
#22This casting of the functions to different argument types constitutes the core of the type safety of the generic invocations; I’m not sure it can be fixed.
Re: I write type-safe generic data structures in C
#23Re: I write type-safe generic data structures in C
#24For your level 2 code, `uint64_t data[];` is wrong for types whose alignment is greater than `uint64_t`, and also wasteful for types whose alignment is smaller (for example, under an ilp32 ABI on 64-bit architectures). For your level 3 code, it should be `int main() { List(Foo) foo_list = {NULL};` Note that working around a lack of `typeof` means you can't return anything. Also, your particular workaround allows `con…
I would love for `union`s to be federated, that is, a type could declare itself as thought it was part of a union with another type, without having to pre-declare all possible types in one place.
Re: I write type-safe generic data structures in C
#25The #1 data structure in any program is array.
Re: I write type-safe generic data structures in C
#26Hi. I object. The trick#0 you mention is how I made an entire C dialect. Here is a generic binary heap, for example https://github.com/gritzko/librdx/blob/master/abc/HEAPx.h The syntax is a bit heavyweight, but a huge huge advantage is: you get regular C structs in the end, very plain, very predictable, very optimizable. Compiler would eat them like donuts. In the other cases, it is void* and runtime memory sizing an…
Made me laugh out loud!
Re: I write type-safe generic data structures in C
#27Re: I write type-safe generic data structures in C
#28Re: I write type-safe generic data structures in C
#29Re: I write type-safe generic data structures in C
#30It is cool trick. I already use in my experimental library though ;-) https://github.com/uecker/noplate/blob/main/src/list.h
I guess if anyone might know it might be you—do you see any way of doing this for intrusive data structures, embedding the node struct in the data (and as side effect supporting an object to be on multiple containers) rather than the data in the node like you're doing there?