Re: ensure function pointer / argument compatibility for apply-like functions

Basile Starynkevitch <[email protected]> Tue, 09 Dec 2025 17:22:18 +0100
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
On Tue, 2025-12-09 at 11:32 +0100, Matthias Pfaller wrote:
> and now for something completely different...
> 
> In our RTOS I have a function called task_create. Originally I declared it as follows:
> 
> struct task *task_create(const char *name, void (*f)(void *), void *farg, unsigned 
> int stacksize, unsigned int priority);
> 
> When the task is created, it is started by calling f(farg). But actually I wanted to 
> be able to declare the task function taking an arbitrary typed argument and I wanted 
> to make sure that the "farg" argument (which also should be of an arbitrary type) 
> passed to task_create matches the prototype of f.
> 
> I came up with the following solution. [...I, Basile S. am skipping interesting details in message by Matthias Pfaller....]

other possibilities which come to mind could be

* build time generation of (specialized C) code, inspired by GNU autoconf or using GNU bison or carburetta.com

* run time generation of specialized code, maybe using asmjit.com or libgccjit (the later requires you to
"embed" most of the GCC compiler as a large library in your code).

I am of course assuming your target platform is a Von Neumann architecture
(code and data in the same address space).

Papers about partial evaluation are also inspirational.

Regards

-- 

Basile STARYNKEVITCH                    basile AT starynkevitch DOT net
8 rue de la Faïencerie                       http://starynkevitch.net/Basile/  
92340 Bourg-la-Reine                         https://github.com/bstarynk
France                                https://github.com/RefPerSys/RefPerSys
                  https://orcid.org/0000-0003-0908-5250