3 ms·
C requires you to understand its conceptual execution and memory layout model in order to write safe code. That is, how the call stack works, the different type
by bluetomcat 8y ago
C requires you to understand its conceptual execution and memory layout model in order to write safe code. That is, how the call stack works, the different types of storage, that each type has alignment requirements, and I'm not even mentioning threading issues.
No amount of syntax sugar on top will prevent you from writing unsafe code, unless that basic model is thrown away.
- pjmlp 8y agoExcept that languages even older than C made those issues easier to track down.
- bluecalm 8y agoYou don't need to know anything about alignment to write normal safe C code. Only when to dive deep into performance optimization you start to worry about those things but hopefully by then you care enough to make sure to check what the language spec allows. Seriously, just don't cast object of one type to another type and you can forget about alignment until you need to optimize.
- MaulingMonkey 8y agoCompiler generated SSE, and multithreading primitives, etc. will break on unaligned access even on relatively unalignment-tolerant x86 chips - to say nothing of stricter ARM CPUs. You need to keep this in mind basically any time you're going from byte buffers to more complicated types. Basically anything touching allocation or IO needs to be aware of it, IMO, even before optimization.
- Too 8y agoQuite the contrary, it's when people think they understand the memory layout, the callstack, the alignment requirements, etc and abuse that knowledge to "optimize" their code or out of sheer laziness you get all the problems of C. Just ignore how things are stored in memory and treat it like Java and you will be just fine. Only difference should be that you have to think about memory allocation and object lifetime/ownership.