Fork me on GitHub
  November 15, 2018, 07:50:29 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Proposed fix: Illegal mix of object and function pointers  (Read 2621 times)
louisdx
Newbie
*
Posts: 12


View Profile
« 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:
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?
Logged
deoxxa
Administrator
Newbie
*****
Posts: 28


View Profile
« 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/
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!