On Tue 22 Mar 2022 at 20:59:05 +0000, Koning, Paul wrote: > > But these sorts of strategies require bigger function pointers, which > > you basically can't do in C. > > Can't you? Does C require function pointers to have the same type, or > compatible structure, as data pointers? No, I don't think that it does. You could have different sizes for those. However there are, I fear, too many programs that somewhere convert a function pointer to (void *) and at that point things break. And there is not really a "generic function pointer type" that you could sensibly use instead, I think. > If it does, that would mean you can't get a pointer to a nested > function, which is no different from the C++ rule that you can't get a > (plain function) pointer to a member function. True. But the trampoline function on the stack are only needed to create a pointer to a nested function. I don't think there is any issue if you never create such pointers. But that would make nested functions a lot less useful. You couldn't use one with qsort(3) for instance (as the comparison function), which is exactly the sort of scenario that would be perfect for a nested function. Possibly, a trampoline could be created on the heap, and then made executable and un-writable. Maybe that's considered too complicated / system dependent / expensive by gcc? > paul -Olaf. -- ___ "Buying carbon credits is a bit like a serial killer paying someone else to \X/ have kids to make his activity cost neutral." -The BOFH falu.nl@rhialto
Attachment:
signature.asc
Description: PGP signature