3 ms·
Static analysis and Valgrind are wonderful. This being said, I think I was six months into using 'C' when I mostly stopped having memory errors. Mainly, you co
by ArkyBeagle 11y ago
Static analysis and Valgrind are wonderful.
This being said, I think I was six months into using 'C' when I mostly stopped having memory errors. Mainly, you construct the operations against memory objects based on building up series of constraints. This is less trouble than it sounds.
You learn to conform to the expectations of the language and libraries. And you use less of 'C' than there is to use. And when things get past a certain level of complexity, I tend towards making them state machines.
Should you have to do that? I have no idea. I do agree that based on most other people's 'C' code, it does appear to be painful for a great many people.
- blub 11y agoDo you have some example? I can't really picture the series of constraints that you mentioned...
- lfowles 11y agoProbably manual RAII. That seems to be where most stable C codebases end up, with a simple object model.
- ArkyBeagle 11y agoRAII type things are part of it. The rest is simply making sure all the constraints are met. The fewer operational constraints, the better. For text I/O parsing, just be semi formal about it at least. Check your indices, be careful of integer overflow and be judicious in the use of floating point. Use block I/O instead of the finer-grained things in stdio.h . Have instrumentation built in that you can enable to capture test vectors ( if you have the resources ). Error counters can tell you a lot. the mechanism of choice for managing complexity tends towards state machines and sometimes message passing. That's a start.