3 ms·
I'm not sure how malloc/free could be considered "advanced" C programming techniques. It's pretty hard to write any non-trivial program in C without using mallo
by greenyoda 13y ago
I'm not sure how malloc/free could be considered "advanced" C programming techniques. It's pretty hard to write any non-trivial program in C without using malloc/free and knowing the differences between static, stack-allocated and heap-allocated memory.
- pfacka 13y agoThe challenging part is to get details of using them correctly and avoid security and portability issues and I consider it neccesaty introduction for section dealing with memory management.
- spc476 13y agoAnd he didn't get all the details right. realloc(valid_pointer,0); IS defined (in C89 no less) to act like free(). It is NOT operating system dependent.
- pfacka 13y agoTrue, but return type of free() is void, thus it says nothing about return value. The POSIX says: "If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned."
- adultSwim 13y agoYou'd be surprised with how far you can get without dynamic memory or recursion... Still, I agree with your general sentiment. That some of these are "advanced" topics is troubling. Too many programmers today don't know how a computer works. Our ideas of "mastery" are way too low.
- erobbins 13y agoin the modern climate of bootcamped rails hackers, knowing that memory even needs to be allocated at some point is advanced.
- Iftheshoefits 13y agoDepends on one's reference point. A lot of people in the web development world (for example) would probably consider manual memory management to be an advanced topic, because typically they've "grown up" with languages where memory management was so removed or abstracted as to be almost irrelevant beyond trivial "do I have enough RAM to hold this array?" type concerns.
- dinkumthinkum 13y agoWell honestly then they are sort of beginners to computer programming. Using malloc is not advanced C programming.