The __callback type qualifier
The keyword __callback
is a qualifier that can
be applied only to a function pointer type. The qualifier instructs the compiler
to generate extra code in the call sites to assist the call, and thus allows
the function pointer to point to either XPLINK or non-XPLINK functions. Under
normal circumstances, a non-XPLINK function pointer is incompatible with XPLINK
compilation units.
int (*__callback foo)(int);
declares foo
to be a function pointer that might point to non-XPLINK functions. foo
will
then have fewer restrictions on what it can reference and can thus be used
with XPLINK compilation units.XPLINK and non-XPLINK compilation units cannot be statically bound;
the two linkages can be mixed only across DLL boundaries. Moreover, a function
pointer that points to a non-XPLINK function cannot be used in XPLINK DLLs
unless the pointer is passed across the boundary explicitly as a function
argument. The __callback
qualifier relaxes the latter restriction,
at the expense of extra code sequences in the call site.
__callback
keyword is a language
extension that has a single effect: to instruct the compiler to generate assistance
code. It does not take part in type definition. The keyword also has no effect
on the following: - Type (such as in overload resolution).
- Name mangling.
- Allocation of the pointer object in memory.
__callback
-qualified for all call
sites that require it.