Is there any way to retrieve a float from a varargs function's parameters?
- by Jared P
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.