3 ms·
Not an entirely uncommon idea. I've written one. There's also a well-known one here, in klib: https://github.com/attractivechaos/klib/blob/master/kvec.h https:
by kzrdude 4y ago
Not an entirely uncommon idea. I've written one.
There's also a well-known one here, in klib: https://github.com/attractivechaos/klib/blob/master/kvec.h https://github.com/attractivechaos/klib/blob/master/kvec.h
- globalreset 4y agoWho didn't. Almost any C program dealing with strings and collections has to have their own implementation or import one. Part of the reason why C developers "feel" productive, but can't produce anything of meaningful complexity.
- rootw0rm 4y agoI think sqlite is fairly complex
- kzrdude 4y agoYou hurt me with the truth. Anyway, I think this HN posting has this "crazy" flavor of using macros to simulate generics, and that's the specific kind of implementation that I meant, which klib also does.
- deleted 4y ago[deleted]
- nice_byte 4y agotil the Linux kernel has no meaningful complexity
- kevin_thibedeau 4y agoStill waiting for a revolutionary OS written in $virtuous_lang to save us from the scourge of unsafe Linux. They've had since Ada-83 to get something off the ground. Guess they aren't so productive either.
- matheusmoreira 4y agoHave you ever heard of Linux?
- rramadass 4y ago>Part of the reason why C developers "feel" productive, but can't produce anything of meaningful complexity. https://quoteinvestigator.com/2010/05/17/remain-silent/ https://quoteinvestigator.com/2010/05/17/remain-silent/
- deleted 4y ago[deleted]
- acmj 4y agoProbably many have written a vector header like this. It baffles me why this one reaches the front page of HN given that the implementation is not that great. A few problems (some have been mentioned by others as well). 1. not using "do {} while (0)". This may lead to compile errors. 2. using uint32_t for capacity. On 64-bit machine, this doesn't save memory. 3. DYN_ARR_RESIZE() may have a quadratic time complexity if some is calling DYN_ARR_RESIZE(a, 10); DYN_ARR_RESIZE(a, 11); DYN_ARR_RESIZE(a, 12) etc in a loop. kv_resize() in kvec.h wouldn't have this problem. 4. Segfault if capacity is 0.
- bigyikes 4y agoIt’s better that the code isn’t perfect. Reading the code review comments in this thread has been really valuable for me personally. Like, I’m not sure I would’ve learned about the do-while trick had so many people not pointed it out.