4 ms·
I disagree. Generating code at runtime like this is a giant can of worms. The right fix is to have a calling convention that allows closures to be passed a cont
by amluto 7y ago
I disagree. Generating code at runtime like this is a giant can of worms. The right fix is to have a calling convention that allows closures to be passed a context parameter, so a closure would be a function pointer and a data pointer. Basically every reasonably modern language can do this. GCC’s hack to shoehorn closures into C couldn’t.
If GCC had a special function pointer type for closures, they would have worked just fine.
- saagarjha 7y agoGCC doesn’t, but Clang does: https://en.wikipedia.org/wiki/Blocks_(C_language_extension) https://en.wikipedia.org/wiki/Blocks_(C_language_extension)
- dooglius 7y agoExcept functions like qsort which are in the standard library wouldn't have such functions in the signature, so the code in the example still wouldn't work.
- amluto 7y agoglibc's qsort_r() takes a callback argument that could be used.