Follow-up Comment #1, patch #4949 (project freeciv): Modern optimising compilers sometimes compile into a branch table, which is precisely as efficient as an array of pointers to pointers to functions (so nearly, but not quite as efficient as an array of pointers to functions), but this isn't always the case, especially in situations where multiple values hit the same code block, or where fallthrough is required (instead choosing a binary search or possibly a sequence of conditionals, depending on the code structure). For the really huge tables, where every possible value has an associated (different) code block, the compiler probably does the right thing, but the code would probably be easier to read and maintain if the functions were smaller and the callers had a constant signature (e.g. in requirements.c, there are all sorts of inconsistencies in whether various conditions are checked in the switch statement or in the function called by the switch statement, which can be confusing when hunting code paths).
My personal preference is that any switch statements that are converted to function arrays maintain a static function array in a .c file which is initialised on program load, rather than hardcoding the arrays in header files and exporting them everywhere. If access is required from other modules, macro accessors can drive a generic handling function that calls into the function array (potentially with localised pre- and/or post-processing). _______________________________________________________ Reply to this item at: <http://gna.org/patch/?4949> _______________________________________________ Message sent via/by Gna! http://gna.org/ _______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev