2 ms·
My mental model of memory in C is that it is unitialized unless otherwise specified. Certainly in higher level languages (e.g., Java, Pyton, Ruby), we expect me
by mcculley 11y ago
My mental model of memory in C is that it is unitialized unless otherwise specified. Certainly in higher level languages (e.g., Java, Pyton, Ruby), we expect memory to be initialized (otherwise garbage collection doesn't work).
Coming to C with a mental model of memory from another language is a recipe for security problems.
- slewis 11y agoYou have the correct mental model, but does the next person who modifies your code?
- qb45 11y agoThen you use valgrind instead of sweeping bugs under the rug. The next person may have equally likely (or maybe more likely?) simply forgotten to initialize some particular field and now you've got a problem if the field is supposed to read 0 most of the time and maybe sometimes 1.