News for hackers. Stuff that matters.
Re:Type-erased generic functions for C: A modest non-proposal by naasking on Thursday October 03, 2024 @09:45AM (#41730756)
That monomorphizes every definition, and the point of this proposal was to avoid that.
Re:Type-erased generic functions for C: A modest non-proposal by rwmj on Thursday October 03, 2024 @10:48AM (#41731312)
That's true, although I wonder if a "sufficiently smart compiler" could combine compatible definitions. Also note it's in a header file and most of these functions are minimal enough they would be inlined.
Re:Type-erased generic functions for C: A modest non-proposal by eqvinox on Thursday October 03, 2024 @11:31AM (#41731691)
I'd distinguish here and not label one-liner "cast wrappers" as monomorphization. And then you can in fact do a lot with macros.

(My definition of a "cast wrapper" is: function body contains exactly one function call, mostly forwarding arguments. Pointer offsets¹ on arguments/retval are allowed, as well as adding sizeof/offsetof/constant integer arguments, but nothing else.)

¹ this may include some conditionals to keep NULL as NULL when applying a pointer offset.

I would expect the compiler to be able to optimize these away in 99% of cases, but TBH I don't care if it doesn't and I'm littering a bunch of small wrapper functions.