Is there any way to retrieve a float from a varargs function's parameters?

Posted by Jared P on Stack Overflow See other posts from Stack Overflow or by Jared P
Published on 2010-05-20T16:10:24Z Indexed on 2010/05/20 16:40 UTC
Read the original article Hit count: 167

Filed under:
|
|

If the function was defined with a prototype which explicitly stated the types of the parameters, eg.

void somefunc(int arg1, float arg2);

but is implemented as

void somefunc(int arg1, ...) { ... }

is it possible to use va_arg to retrieve a float? It's normally prevented from doing this because varargs functions have implicit type promotions, like float to double, so trying to retrieve an unpromoted type is unsupported, even though the function is being called with the unpromoted type do to the more specific function prototype.

The reason for this is to retrieve arguments of different types at runtime, as part of an obj-c interpreter, where one function will be reused for all different types of methods.

This would be best as architecture independent (so that if nothing else the same code works on simulator and on device), although if there is no way to do this then device specific fixes will be accepted.

© Stack Overflow or respective owner

Related posts about c

    Related posts about objective-c