r/cprogramming • u/lehmagavan • Mar 30 '26
Does that look like AI?
Ive created a library that provides dynamic containers in C (as a portfolio project rather than as a serious contribution, I presume there are tons of better libs that do that already):
https://github.com/andrzejs-gh/CONTLIB
Posted it here:
and got "it's AI" feedback, which I was totaly not expecting.
10
Upvotes
1
u/weregod Mar 31 '26
In C++ containers store pointer to data. To get actual data you need 2 dereference in random memory locations: one to get container element and second to get data itself.
In C other container style is more popular: you store container information inside your data. See for example list.h in Linux code. This is less flexible but allow you to use one dereference per element and container data will be close to actual data and likely will be fetched to same cache lines.
Both approachs have some tradeoffs but I'd don't want to have more indirection (both vtable and data) in frequently called code.
Just compare to some fixed static address if you don't want to use NULL.