4 ms·
Personally, I'd like to see some of these features added to C where they make sense. Raw strings, bind, lambdas, constexpr, and ranged for loops would all make
by JoshTriplett 13y ago
Personally, I'd like to see some of these features added to C where they make sense. Raw strings, bind, lambdas, constexpr, and ranged for loops would all make sense in C.
- gcr 13y agoHow could lambdas make sense in C? Keeping closures around means having to keep free variables around. C doesn't have garbage collection, so it would be quite awkward to establish conventions about who gets to free the variables that each closure references.
- betterunix 13y agoHow does any of that not apply to C++?
- deleted 13y ago[deleted]
- kybernetyk 13y agoClosures work pretty great with std::shared_ptr.
- betterunix 13y agoUnless you have a cycle.
- JoshTriplett 13y agoTake a look at the "blocks" extension to C, in LLVM. It includes mechanisms to handle the lifetime issues, though it does still require explicit memory reclamation of blocks.
- iambvk 13y agoI agree! I found no libraries that give std::bind functionality in C and GCC extensions also doesn't offer any solutions.
- smegel 13y agoThe main thing C needs from C++ is object destructors and RAII. It would be easy to denote a function as the cleanup operator for a struct, and the compiler already knows when variables go out of scope, valuable information that is currently not used for much. auto/shared pointers would save a lot of memory management pain in C. Also function templates that would allow such things as a fast generic sort routine without lots of function pointer dereferences would be nice. There's nothing else in C++ i can't live without.