Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.




Except 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.


glibc's qsort_r() takes a callback argument that could be used.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: