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•1h 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

Xpm – Universal Package Manager Wrapper

https://twitter.com/simonfarshid/status/1972093256101253537
1•sfarshid•5m ago•0 comments

You'll still need a Microsoft account for Windows 10 ESU in Europe

https://www.windowslatest.com/2025/09/26/no-youll-still-need-a-microsoft-account-for-windows-10-e...
1•swat535•23m ago•0 comments

Enthusiasts bond twelve 56K modems together to set dial-up record: 668kbps

https://www.tomshardware.com/networking/enthusiasts-bond-twelve-56k-dial-up-modems-together-to-se...
2•wrayjustin•23m ago•0 comments

The Open Printer Is a Raspberry Pi Zero W-Powered Printer

https://www.hackster.io/news/the-open-printer-is-a-raspberry-pi-zero-w-powered-fully-open-highly-...
3•nmstoker•24m ago•0 comments

Severed and softening core columns, not failing floors, triggered WTC collapse

https://www.metabunk.org/threads/kostack-studios-wtc2-south-tower-collapse-simulation.14468/
1•BostonFern•28m ago•0 comments

Drills vs. Hammer Drills vs. Impact Drivers

https://thewoodwhisperer.com/articles/drills-vs-hammer-drills-vs-impact-drivers/
1•behnamoh•38m ago•1 comments

The missing layer in the modern data stack

https://www.dimensionlabs.io/blog/the-missing-layer-in-the-modern-data-stack-unstructured-data
1•ericdlg•39m ago•0 comments

Advent of Code: Libraries

https://elly.town/d/blog/2025-09-17-advent-of-code-libraries.html
1•amcclure•42m ago•0 comments

Much-loved Osterley Bookshop saved from closure after public support

https://www.ianvisits.co.uk/articles/much-loved-osterley-bookshop-saved-from-closure-after-public...
1•ggandhi•45m ago•0 comments

Competition in the classroom: When incentive systems change character

https://phys.org/news/2025-09-competition-classroom-incentive-character.html
1•PaulHoule•46m ago•0 comments

The Heroic Remains of Homer's Odyssey

https://www.historytoday.com/archive/making-history/heroic-remains-homers-odyssey
1•tintinnabula•55m ago•0 comments

GitHub Wiki Search Engine Enablement

https://github-wiki-see.page/
2•turtleyacht•1h ago•1 comments

Suzuki's new logo is a modern triumph

https://www.creativebloq.com/design/logos-icons/suzukis-new-logo-is-a-modern-triumph
1•vinhnx•1h ago•0 comments

UK government underwriting £1.5B loan to Jaguar Land Rover after cyber-attack

https://www.theguardian.com/business/2025/sep/27/jaguar-land-rover-plans-to-restart-engine-manufa...
14•echelon_musk•1h ago•0 comments

The Origins of PyCharm

https://www.youtube.com/watch?v=lze9mvqGgUQ
2•ceolin•1h ago•0 comments

Reports: EA set to be sold to private investors for up to $50B

https://arstechnica.com/gaming/2025/09/reports-ea-set-to-be-sold-to-private-investors-for-up-to-5...
13•hackthemack•1h ago•2 comments

Detecting Surveillance Cameras with the ESP32

https://hackaday.com/2025/09/26/detecting-surveillance-cameras-with-the-esp32/
4•toomuchtodo•1h ago•0 comments

Compiling Python to Run Anywhere

https://blog.codingconfessions.com/p/compiling-python-to-run-anywhere
2•vinhnx•1h ago•0 comments

Warner Bros Joins Disney in Suing Sling TV for Making Streaming Video Cheaper

https://www.techdirt.com/2025/09/26/warner-bros-joins-disney-in-suing-sling-tv-for-making-streami...
4•voxadam•1h ago•0 comments

Austria's military just ditched Microsoft for open-source LibreOffice

https://www.zdnet.com/article/this-european-military-just-ditched-microsoft-for-open-source-libre...
8•CharlesW•1h ago•1 comments

Learn to Play Go

https://online-go.com/learn-to-play-go
2•kqr•1h ago•0 comments

Incentives and Outcomes in Humans, AI, and Crypto

https://olshansky.info/posts/2025-09-27-ai-crypto-human-incentives
1•Olshansky•1h ago•0 comments

The Extraordinary Rise of Electric Cars in Developing Countries

https://www.bloomberg.com/news/articles/2025-09-25/the-extraordinary-rise-of-electric-cars-in-dev...
3•thinkcontext•1h ago•0 comments

Show HN: Create process, data and component diagrams from natural language

https://www.diagramguru.com/
1•vaneyckseme•1h ago•0 comments

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

https://github.com/RolandMarchand/vector.h
1•Moowool•1h ago•0 comments

SecureBitchat End-to-end freedom v4.02.985

https://github.com/SecureBitChat/securebit-chat
2•SecureBitChat•1h ago•2 comments

The Lowest Level PL

https://pramatias.github.io/cubes/cubes_en.html
1•emporas•1h ago•1 comments

Spending on AI Is at Epic Levels. Will It Ever Pay Off?

https://www.wsj.com/tech/ai/ai-bubble-building-spree-55ee6128
21•RyanShook•1h ago•17 comments

Faster Virtual Machines: Speeding Up Programming Language Execution (2023)

https://mort.coffee/home/fast-interpreters/
1•ofalkaed•1h ago•0 comments

America's Elite Colleges Breed High-Status Careers–and Misery

https://www.motherjones.com/politics/2025/09/elite-ivy-league-colleges-endowment-inequality-caree...
8•ryan_j_naughton•1h ago•2 comments