View Single Post
Old November 13, 2016, 21:01   #2
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,446
Derakon is on a distinguished road
If I understand the question correctly, you're trying to figure out how to identify a) what function needs to be invoked, and b) what parameters to pass to the function, at runtime? If so, then yes, absolutely, the explicitly coupled version is superior to using preprocessor hacks, if only for readability -- the problem I have with the preprocessor directives is that functions get defined/invoked "magically" -- there's not an obvious path in the code to get from point A to point B because the code as written isn't complete.

The value_bases array in the second example is much more like what I'd aim for. It's effectively a manually-created dispatch table, where you use a string to look up the function you want to invoke. Then someone reading the code can say "ah, this function is going to invoke one of these other functions depending on the value of this string"; nice and straightforward to comprehend.
Derakon is offline   Reply With Quote