Question 15.10

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. See also questions 11.3 and 15.2.

References: ANSI Sec. 3.3.2.2
ISO Sec. 6.3.2.2
Rationale Sec. 4.8.1.2
H&S Sec. 11.4 p. 297


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback