Mineserver > Development
Proposed fix: Illegal mix of object and function pointers
(1/1)
louisdx:
I changed the compiler flags to "-W -Wall -pedantic", and was immediately inundated in warnings. I believe that serious, robust server design should try to be as clean and correct as possible at all levels, so I am hoping that you will forgive my pedantry.
I would like to propose a change, mainly to "hook.h" (but also "plugin_api.*") which will entail many changed lines, but just one conceptual modification, so kindly bear with me:
I would like to replace the void* which is used to store function pointers the m_callbacks vector by a genuine void function pointer:
--- Code: ---typedef void (voidF*)();
typedef std::pair<void*, voidF> callbackType
--- End code ---
Every instance of "void* function" has to be replaced by "voidF function", but the change is straight-forward. It works like a charm in my fork.
Rationale: The C++ standard prohibits using object pointers to store function pointers. With this change the code will be more standard conforming and thus more portable. Also, it is philosophically The Right Thing ;-)
Slightly unrelatedly, "hook.h" is HUGE -- how is your position on switching to C++0x, so we could use variadic templates?
deoxxa:
Ah, yes, hook.h. That is (or was) entirely machine-generated code (see tiny-cplusplus-callbacks), designed simply as a stopgap measure that just seemed to keep working far past its intended lifecycle. If you have an idea that will take mineserver a step in the right direction and are willing to put in a little time on it, I don't think any of the core devs will have any reservations on the matter.
TL;DR: s/hook.h/horrible.h/
Navigation
[0] Message Index
Go to full version