Paul Eggert wrote:
> The only think I can think of, other than assembler, is to convert every API 
> to (int dummy, ...) form, and then to use stdarg for every actual argument 
> while ignoring the dummy. This form should work with both C23 and pre-C23

Yes, that would be a way to write code that is C23 compliant and works
on macOS. But it's a heavy change of the code.

> I assume it's a dynamically generated API. Are you trying to link C23 code 
> with pre-C23 code?

Not even that. All code being compiled by the same compiler in C23 mode.

Two examples:

a) In an embedded language interpreter with functions, we would have
     int f_gcd (int x, int y);
     int f_minus (int x);
     ... // 500 more functions like this
   and want to invoke them through a function pointer in a central place
   (not 100 different types of function pointers).

b) libffcall's <trampoline.h>:
       
/* This type denotes an opaque function pointer.
   You need to cast it to an actual function pointer type (with correct return
   type) before you can actually invoke it. */
#if defined __cplusplus || __STDC_VERSION__ >= 202300L
typedef int (*trampoline_function_t) (...);
#else
typedef int (*trampoline_function_t) ();
#endif

/* Allocates a trampoline.
   It returns a function pointer that takes the same parameters and returns the
   same type as ADDRESS.
   When invoked, it first stores DATA at the location pointed to by VARIABLE,
   then invokes ADDRESS with the same arguments. It returns the value returned
   by ADDRESS.  */
extern trampoline_function_t alloc_trampoline (trampoline_function_t /* ADDRESS 
*/, void** /* VARIABLE */, void* /* DATA */);

The "takes the same parameters" thing does not work any more since
ADDRESS was a normally defined function that gets its first 8 arguments
in registers (x0..x7), whereas the returned function on macOS gets
the first 8 arguments passed on the stack.


Any workaround that comes to mind?

Bruno




Reply via email to