https://gitlab.com/nbdkit/nbdkit/-/blob/296b9dd041fdbcbaa731...
https://gitlab.com/nbdkit/nbdkit/-/blob/296b9dd041fdbcbaa731...
#define VECTOR_TYPE int #include “vector.h”
This will let you step into the macro generated functions in GDB and doesn’t require putting the function creation in macros (no backslashes, can write the implementations like normal code)
You can also get syntax like this that way Vector_Push(int)(&vec, 1);
Which imo does a better job distinguishing the type from the name
TBH, rather than fancy high-meta generic support, I'd be much more appreciative of ISO C adding something like "_Include" to the preprocessor, e.g.
#define DEFINE_MY_WRAPPER(foo, bar) _Include("wrapper.h")
/* "foo", "bar" remain accessible in wrapper.h */
I tried implementing this in GCC but didn't get very far, it runs a bit counter to how includes are handled currently.P.S.: I ended up doing this https://github.com/FRRouting/frr/pull/15876/files#diff-90783... instead; a tool that can be invoked to expand some DEFINE_FOO if needed for debugging. It's not used particularly often, though.
(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.