I recently started a small personal project (RGB value BGR value conversion program) in C, and I realized It happened that changing a function from RGB to BGR could not only be a conversion but also inverted. Obviously this means that I do not really need two functions rgb2bgr
and bgr2rgb
though, does it make a difference that uses the function pointer instead of the macro ? For example:
int rgb2bgr (const int rgb); / * * Should I do this because it allows the compiler to issue a proper error message using the appropriate function name, * to not mention possible debugging profits? * / Int (* bgr2rgb) (const int bgr) = rgb2bgr; / * * Or should I do this because it is only a feature and they are actually the same function? * / #define bgr2rgb (bgr) (rgb2bgr (bgr))
I do not necessarily seek a change in performance efficiency because it is more of a subjective question than curiosity. I am well aware that type protection is neither lost nor obtained by law. Will the function pointer be the only feature or will it be more practical benefits that I am unaware of?
Another possibility is that the second function calls the call first and let the compiler worry about optimizing it (tail call Inline or create)
Comments
Post a Comment