4 ms·
if that meets the semantics of what you’re trying to do, great. but often in programming it’s not. the depth of the copy you want depends on what you’re trying
by cobbzilla 8y ago
if that meets the semantics of what you’re trying to do, great. but often in programming it’s not. the depth of the copy you want depends on what you’re trying to do. copying pointers (or references, or whatever might point to dynamically allocated memory) by value means using a garbage collector or reference counting mechanism, or risk a memory leak.
- kjeetgill 8y agoIt's C. If you think being specific about what you want copied, freeing only when you know it's appropriate, and tracking any metadata around that yourself if a problem, don't work in C. Get it right or risk a memory leak is the name of the game.
- cobbzilla 8y agoIt’s your program. The suggestion was that copy-everything-by-value solves the closure/memory issue with respect to copies. It does not. This is also why C doesn’t have closures. Ships passing in the night...
- geezerjay 8y ago> It’s your program. No, it's the C programming language. It has been like that since the 70s, and lots of people have been using it to develop high availability software for decades. Just because some people never learned its basics nor are familiar with the subject that doesn't mean they have a point. > The suggestion was that copy-everything-by-value solves the closure/memory issue with respect to copies. No, that's quite wrong. The suggestion was thay passing objects by value would enable capturing variables without any of the slippery slope nonsense that was pointed out. > This is also why C doesn’t have closures. No, that's quite wrong as well. C doesn't have closures because no one bothered to add them, which is the exact same reason why C doesn't have namespaces or generics or any other feature ever. That's it.
- djur 8y agoC has generics (within the limitations of its type system) since C11. https://en.cppreference.com/w/c/language/generic https://en.cppreference.com/w/c/language/generic