<!-- begin site header -->
<div id=

Author Topic: Proposed fix: Illegal mix of object and function pointers  (Read 13243 times)


  • Newbie
  • *
  • Posts: 12
    • View Profile
Proposed fix: Illegal mix of object and function pointers
« on: April 01, 2011, 07:20:51 pm »
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: [Select]
typedef void (voidF*)();
typedef std::pair<void*, voidF> callbackType

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?


  • Administrator
  • Newbie
  • *****
  • Posts: 28
    • View Profile
Re: Proposed fix: Illegal mix of object and function pointers
« Reply #1 on: June 11, 2011, 04:51:15 pm »
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/