4 ms·
The main footman in C for novices is memory handling. -Separate all memory creation and destruction(anything that has a malloc and free on it) and handling of
by cracrecry 3y ago
The main footman in C for novices is memory handling.
-Separate all memory creation and destruction(anything that has a malloc and free on it) and handling of it into independent modules(files).
-Automate the above memory creation and destruction with a language like CLisp or Clojure so everything that access memory uses the same code that is well tested and minimal. Creating primitive equivalents to C++ vectors or node handling is extremely useful.
Wit automation you can warrantee that everything allocated is freed, but if you are not used to meta programming you can start doing it manually.
-Always use limited arrays for accessing things and structures, use single digits globals in your entire program. The complex pointers' arithmetic should be limited to the memory isolated modules and only should be done if you really know what you are doing.
-Never be too "smart", write simple code. Do not use more that "pointers to pointers" complexity(forbidding things like pointers to pointers to pointers). Create multiple simple lines instead of long sophisticated ones.
-Use Valgrind, specially in the isolated modules and always make it to have 0 warnings.
-If you use Xcode, learn to use the debugger(lldb) for sophisticated debugging(learn about breakpoints, watchdogs and printing variables). If you learn the text commands you will be able to use it anywhere(command line, vim or emacs), in any OS(windows, linux, Mac, WebAssembly).