2 ms·
Consider the following: * one slot for a variadic function pointer * another slot for a datum that fully describes the function signature for the function the
by jancsika 7y ago
Consider the following:
* one slot for a variadic function pointer
* another slot for a datum that fully describes the function signature for the function the first slot points to.
This allows the programmer to specify whatever types the interface allows in parameters of the function callback. Otherwise the programmer must use a catchall interface like "argc, argv" and then add steps inside the function body to fetch the args. At least in my experience programmers screw up way more often with the catchall interface than they do with typing the correct function parameters.
There's just one "tiny" problem with this approach. :)
Nevertheless I've seen this technique in old code that still runs on every modern architecture on which someone bothered to compile it. Gcc doesn't complain about the tiny problem unless you use emscripten to compile to web assembly. (And even there you can still get away with undefined behavior as long as the number of parameters agree.)