c++haxehxcpp

What does ret reinterpret_cast do?


#define HX_DEFINE_DYNAMIC_FUNC0(class,func,ret) \
Dynamic __##class##func(hx::Object *inObj) \
{ \
      ret reinterpret_cast<class *>(inObj)->func(); return Dynamic(); \
}; \
Dynamic class::func##_dyn() \
{\
   return hx::CreateMemberFunction0(this,__##class##func); \
}

The above CreateMemberFunction0 is a struct that holds information about the function. The function __##class##func is presumably at some point executed and its result is passed to relevant code. However, I am confused by this because it appears that the execution of the function returns the execution of a function called Dynamic? Dynamic is also a class (for those unfamiliar) with hxcpp/haxe.

  1. Is Dynamic() an execution of a function or is it a no-argument construction on the stack of an object?
  2. What is the ret keyword?
  3. If 1 is correct, how is the result of execution of the function passed?

Solution

  • Is Dynamic() an execution of a function or is it a no-argument construction on the stack of an object?

    It must be the latter because the return type of the function being defined is also Dynamic.

    What is the ret keyword?

    It's not a keyword, it's a parameter passed to the macro. A Google search turned up these two use cases of that macro:

    HX_DEFINE_DYNAMIC_FUNC0(List_obj,first,return)
    HX_DEFINE_DYNAMIC_FUNC0(List_obj,clear,(void))
    

    In the first case the function reinterpret_casts the result of the (inObj)->func() function call to a List_obj *. For the code to work, Dynamic must have an implicit conversion constructor that takes a List_obj *.

    In the second case the result of the reinterpret_cast is discarded and a default constructed Dynamic() object is returned.