Basic and Advance C Question:
I have a varargs function which accepts a float parameter
Answer:
I have a varargs function which accepts a float parameter. Why isn't
va_arg(argp, float)
working?
In the variable-length part of variable-length argument lists, the old ``default argument promotions'' apply: arguments of type float are always promoted (widened) to type double, and types char and short int are promoted to int. Therefore, it is never correct to invoke va_arg(argp, float); instead you should always use va_arg(argp, double). Similarly, use va_arg(argp, int) to retrieve arguments which were originally char, short, or int. (For analogous reasons, the last ``fixed'' argument, as handed to va_start, should not be widenable, either.)
va_arg(argp, float)
working?
In the variable-length part of variable-length argument lists, the old ``default argument promotions'' apply: arguments of type float are always promoted (widened) to type double, and types char and short int are promoted to int. Therefore, it is never correct to invoke va_arg(argp, float); instead you should always use va_arg(argp, double). Similarly, use va_arg(argp, int) to retrieve arguments which were originally char, short, or int. (For analogous reasons, the last ``fixed'' argument, as handed to va_start, should not be widenable, either.)
Previous Question | Next Question |
I cant get va_arg to pull in an argument of type pointer-to-function. | My compiler isnt letting me declare a function |