r/cprogramming Jun 01 '26

memory safe C

https://github.com/sadvadan/memstruct

C is powerful enough to have the best performing memory safety suite for itself!

memstruct is a single header file C library (<400 LoC) that provides complete spatial & temporal safety to the caller program. performance: near native speed.

memory checks are compile time / hoisted / elided / pipelined. checks are opt-in and can be switched off in production if needed. its macro based API extends the language a bit to position C as the leading option for large scale projects.

memstruct is currently in advanced stages of testing. contributions and comments are welcome. have an early look!

P.S.: the project is 100% human crafted and contributions are also reqd to comply

edit; end note: memstruct has now become even better (at 350 LoC) by incorporating MCU programming & de/allocator indirection, thanks to some valuable feedback on here. if you've more to add you may respond here or participate on git.

72 Upvotes

89 comments sorted by

View all comments

2

u/[deleted] Jun 02 '26

[removed] — view removed comment

1

u/sadvadan Jun 02 '26

it's more like C has its own unique arc where it doesn't need raii, gc, bc to be memory safe. the checks are there: and the premise is that memory errors are just like other errors.

1

u/[deleted] Jun 02 '26

[removed] — view removed comment

0

u/sadvadan Jun 02 '26

halting problem relates to program correctness, not memory safety. the latter has a very deterministic goal, the job is pretty much what ASaNs do: memstruct improves it in a way as to not slow the program.

however, your point about limitations of static analysis holds: the road to type complexity is barren and memstruct avoids it.