5 ms·
Having learned Rust and used it for nearly 2 years, I am now happy using C. I think most issues in C are easily catchable. Here me out: 1. If using Int for ind
by viperscape 9y ago
Having learned Rust and used it for nearly 2 years, I am now happy using C. I think most issues in C are easily catchable. Here me out:
1. If using Int for indexing or any sort of len or count, make sure it's positive when needed, and within bounds of what's allocated. As in if you plan on allocating huge data, plan it out and use the right data type.
2. If you alloc, then free when done. If you free, set to Null; and before you free, check for Null.
3. If you realloc, in particular, check that it actually worked and prepare for basic error handling.
Rust requires all of these steps by default.
Finally, just test some of your code. Rust makes this easy, and encourages it.
I still really like C.
- wott 9y ago> before you free, check for Null. You can free(NULL), no problem. It will not do anything.
- syockit 9y agoIt's usually a problem with pointers to structs that have pointer members. In a typical destruction sequence, you usually free the members before the struct itself.
- solidsnack9000 9y agoAlthough I completely disagree with you, I really appreciate that you posted.