Hi Petter, On Fri, 2024-12-13 at 16:28 +0100, Petter Reinholdtsen wrote: > [Jean Delvare] > > Petter, is this more in line with how you think this should be > > implemented? > > Sorry for the late reply, I failed to notice your question here. > > The following patch is more in line with what I had in mind, avoiding > the wrapper methods and using macros to redirect the call. Note the > struct ofmt_ and the variable ofmt can not have the same name. > (...)
OK, thanks for the patch. Good to know this is technically possible. That being said, I can't say I'm thrilled. For one thing, even though the overhead is way less than with wrapper functions, there's still a small overhead compared to simple function pointers as every calling location needs to apply an offset to find the actual function address. For another, the need to define the macros last in the header file and undefine them in dmioutput.c makes this approach look a little fragile. Your original reason for not going with a "static" set of function pointers but instead using a struct of them was that it would "allow for some extra flexibility". Could you elaborate on this? To be honest, I don't see the practical benefit. With my original patch, adding a new output format would require assigning all output functions in a new case in set_output_format(), while with yours, one would have to define a struct with the same functions and assign the struct in set_output_format(). Doesn't seem very different to me. Adding a new output function would also be pretty similar (adding it to all cases in function set_output_format vs. adding it to all output format structures). Also note that, if there's really a benefit to grouping all output functions in a struct, this *can* be done using direct function pointers (no wrapper functions, no macros). I have a variant of my first patch doing exactly this. Thanks, -- Jean Delvare SUSE L3 Support