frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: I built type-safe dynamic arrays for C after struggling with stb_ds.h

https://github.com/RolandMarchand/vector.h
1•Moowool•4mo ago
C doesn't come with dynamic data structures like vectors or hashmaps, so developers have to either develop their own on top of arrays and structs, or use an external library.

One of the most popular data structure libraries is stb_ds.h. It's a very easy to use single-header library that feels almost like Javascript arrays, but I was getting frustrated with its design.

First, iteration relies on index calculations, which is a slower technique than pointer comparison (that's what std::vector uses).

Second, the structure hides its array header behind the data pointer. This is done to allow for the square brackets syntax [ ], but it turns debugging into a horrible experience since we can't easily access the header, and this technique relies on undefined behavior which is unreliable, especially when using less popular compilers on different systems.

Third, stb_ds.h doesn't do bounds checking, so it silently corrupts memory out-of-bounds access. This is the worst possible way to manage errors, but C is limited on that department.

Fourth, stb_ds.h isn't fully type-safe. It relies on sizeof (a) for type-checking, but it's possible to pass different pointer types (char, double), different primitives of the same size (int, float), or different structs of the same size (struct { node next; }, struct { float x; float y; }) to violate the type contract. The user must enforce type-safety themselves.

Fifth, I personally do not like its licensing because MIT forbids re-licensing, and public domain is ambiguous internationally.

So I decided to make my own single-header vector library to fix all of those issues.

My vector library (vector.h) uses the same iteration technique as std::vector (3 pointers, one for the beginning of the array/elements, one for past the last element, and one past the last valid memory index). This results in faster iteration (which is the most common array usage), clearer debugging with all values being in the struct, and no undefined behavior surprises.

vector.h also panics on errors instead of silently corrupting memory. This may seem like a bad design decision, but lots of popular languages crash on out-of-bounds access (Rust, Go, GDScript, etc.). It's almost always a severe bug, and it's best to let the developer know by failing fast. But for those who cannot afford a crash, I implemented the flag VECTOR_NO_PANIC_ON_OOB that turns out-of-bounds access into no-ops.

The type-safety requirement was the trickiest to solve, but I landed on macro-generated functions. This is similar to what the Linux kernel sometimes uses like `list.h`, but Linux compiles with gnu89 which includes typeof(), while my vector is strict c89 ISO compliant, which doesn't have typeof().

Finally, for licensing, I chose the BSD Zero-Clause license which allows for re-licensing, is internationally unambiguous, and doesn't require attribution.

To make my library production ready, I included a robust test routine.

I'd love feedback from C developers who've struggled with similar issues. Code and benchmarks at https://github.com/RolandMarchand/vector.h

Show HN: Moli P2P – An ephemeral, serverless image gallery (Rust and WebRTC)

https://moli-green.is/
1•ShinyaKoyano•3m ago•0 comments

How I grow my X presence?

https://www.reddit.com/r/GrowthHacking/s/UEc8pAl61b
1•m00dy•5m ago•0 comments

What's the cost of the most expensive Super Bowl ad slot?

https://ballparkguess.com/?id=5b98b1d3-5887-47b9-8a92-43be2ced674b
1•bkls•5m ago•0 comments

What if you just did a startup instead?

https://alexaraki.substack.com/p/what-if-you-just-did-a-startup
1•okaywriting•12m ago•0 comments

Hacking up your own shell completion (2020)

https://www.feltrac.co/environment/2020/01/18/build-your-own-shell-completion.html
1•todsacerdoti•15m ago•0 comments

Show HN: Gorse 0.5 – Open-source recommender system with visual workflow editor

https://github.com/gorse-io/gorse
1•zhenghaoz•15m ago•0 comments

GLM-OCR: Accurate × Fast × Comprehensive

https://github.com/zai-org/GLM-OCR
1•ms7892•16m ago•0 comments

Local Agent Bench: Test 11 small LLMs on tool-calling judgment, on CPU, no GPU

https://github.com/MikeVeerman/tool-calling-benchmark
1•MikeVeerman•17m ago•0 comments

Show HN: AboutMyProject – A public log for developer proof-of-work

https://aboutmyproject.com/
1•Raiplus•17m ago•0 comments

Expertise, AI and Work of Future [video]

https://www.youtube.com/watch?v=wsxWl9iT1XU
1•indiantinker•18m ago•0 comments

So Long to Cheap Books You Could Fit in Your Pocket

https://www.nytimes.com/2026/02/06/books/mass-market-paperback-books.html
3•pseudolus•18m ago•1 comments

PID Controller

https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller
1•tosh•23m ago•0 comments

SpaceX Rocket Generates 100GW of Power, or 20% of US Electricity

https://twitter.com/AlecStapp/status/2019932764515234159
2•bkls•23m ago•0 comments

Kubernetes MCP Server

https://github.com/yindia/rootcause
1•yindia•24m ago•0 comments

I Built a Movie Recommendation Agent to Solve Movie Nights with My Wife

https://rokn.io/posts/building-movie-recommendation-agent
4•roknovosel•24m ago•0 comments

What were the first animals? The fierce sponge–jelly battle that just won't end

https://www.nature.com/articles/d41586-026-00238-z
2•beardyw•32m ago•0 comments

Sidestepping Evaluation Awareness and Anticipating Misalignment

https://alignment.openai.com/prod-evals/
1•taubek•32m ago•0 comments

OldMapsOnline

https://www.oldmapsonline.org/en
1•surprisetalk•35m ago•0 comments

What It's Like to Be a Worm

https://www.asimov.press/p/sentience
2•surprisetalk•35m ago•0 comments

Don't go to physics grad school and other cautionary tales

https://scottlocklin.wordpress.com/2025/12/19/dont-go-to-physics-grad-school-and-other-cautionary...
2•surprisetalk•35m ago•0 comments

Lawyer sets new standard for abuse of AI; judge tosses case

https://arstechnica.com/tech-policy/2026/02/randomly-quoting-ray-bradbury-did-not-save-lawyer-fro...
5•pseudolus•35m ago•0 comments

AI anxiety batters software execs, costing them combined $62B: report

https://nypost.com/2026/02/04/business/ai-anxiety-batters-software-execs-costing-them-62b-report/
1•1vuio0pswjnm7•36m ago•0 comments

Bogus Pipeline

https://en.wikipedia.org/wiki/Bogus_pipeline
1•doener•37m ago•0 comments

Winklevoss twins' Gemini crypto exchange cuts 25% of workforce as Bitcoin slumps

https://nypost.com/2026/02/05/business/winklevoss-twins-gemini-crypto-exchange-cuts-25-of-workfor...
2•1vuio0pswjnm7•37m ago•0 comments

How AI Is Reshaping Human Reasoning and the Rise of Cognitive Surrender

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=6097646
3•obscurette•37m ago•0 comments

Cycling in France

https://www.sheldonbrown.com/org/france-sheldon.html
2•jackhalford•39m ago•0 comments

Ask HN: What breaks in cross-border healthcare coordination?

1•abhay1633•39m ago•0 comments

Show HN: Simple – a bytecode VM and language stack I built with AI

https://github.com/JJLDonley/Simple
2•tangjiehao•42m ago•0 comments

Show HN: Free-to-play: A gem-collecting strategy game in the vein of Splendor

https://caratria.com/
1•jonrosner•43m ago•1 comments

My Eighth Year as a Bootstrapped Founde

https://mtlynch.io/bootstrapped-founder-year-8/
1•mtlynch•43m ago•0 comments