wide function pointer type

Kaz Kylheku (libffi) 382-725-6798@kylheku.com
Sun Oct 10 17:01:37 GMT 2021


On 2021-10-10 04:32, Martin Uecker via Libffi-discuss wrote:
> Hi all,
> 
> I will propose a wide function pointer type (actually
> a wide function type) to WG14 for C23 as a common
> type for callbacks, closures, which now require an
> additional void pointer argument in C APIs. This
> is intended to be compatible with ABIs with now
> use a static chain register.

Opposed. There is nothing wrong with separate arguments
for function pointer and context.

Higher level languages that interface C or are built on C
do not agree on an exact representation for closures;
it's not a good idea to second guess them. Many languages
are perfectly able, in their implementations, to represent
function callable objects of all sorts using ordinary
pointer-sized reference values. What those values refer to
varies quite a bit.

Callback mechanisms are often bound to OOP-style objects
rather than closures. The same context pointer is
associated with more than one callback.

The context argument has the right flexibility to cover
all the situations that arise.

In some library API's, the object pointer is registered
separately, and then other functions implicitly use it
when invoking callbacks, so it doesn't have to be passed
any more.

Sometimes there are multiple callbacks, but one context
pointer, passed in one call:

   initiate_operation(arg, callback_context,
                      get_data_fn, progress_fn);

Should there be a triple wide pointer just to roll three
arguments into one?



More information about the Libffi-discuss mailing list