API methods with returns and output parameters

edited October 2013 in General discussions
Something I have been curious about in the orx API for some time but I never remember to ask....

Take this method for example:

orxObject_GetSize
http://orx-project.org/orx/doc/html/group__orx_object.html#gaf6f62a36ba59e6bcec6fd56bce495932

There is a return vector with the size result of an object, but there is also an output vector parameter in the method's signature which must be supplied.

Why would there be a return vector? Is it a convenience thing somehow?

Comments

  • jimjim
    edited October 2013
    I too have found this, e.g. orxObject_GetSpeed, returns a vector and takes a vector parameter. But I cant get return value without using a pointer, so I have to new orxVector in order to use return. For stack allocated vectors I have to pass them as parameter.

    So, the return value is not returned as value but as pointer ?
  • edited October 2013
    You're right, the return value is only for convenience.
    The allocation is always the responsibility of the caller. Most of the time, if not always, the structure should be allocated on the stack.

    As for the convenience part (call chaining), here's an example:
    // Scaling an object by a factor of 2
    orxVECTOR vSize;
    orxObject_SetSize(pstObject, orxVector_Mulf(orxObject_GetSize(pstObject, &vSize), orx2F(2.0)));
Sign In or Register to comment.