Say I am developing a Math library and I want it to be such that it will detect whether or not user's machine support SSE (and which version) and based on that, different functions will be called. I can think of three ways to implement that:

  1. Have global function pointers in the library and let user call mathInit() i their source. When they do, figure out the hardware details and assign the function pointers to different functions.

  2. Same, except instead of having global function pointers, put them in a struct which is returned by mathInit(). This way, user will have to call math.vec3Add(...) or similar.

  3. Same as 1, but instead of having global pointers, make mathInit() a macro so that the function pointers will have local scope in user's main() function (and require mathInit() to be called from main()).

Is any of these methods preferable? Is there some other, better way?


Browse other questions tagged or ask your own question.