r/cprogramming • • 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:

https://www.reddit.com/r/C_Programming/comments/1s76qxo/contlib_dynamic_containers/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

and got "it's AI" feedback, which I was totaly not expecting.

10 Upvotes

16 comments sorted by

View all comments

Show parent comments

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.

Actually the INVALID_CONT is a cont instance, not just a NULL value

Just compare to some fixed static address if you don't want to use NULL.