本文介绍了可变参数函数(在va_arg)不使用float工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可变参数函数,它接受一个浮点参数。为什么不工作?

 的va_arg(阿根廷,浮动)


解决方案

的对应 ... 函数的参数的推荐的传球前你的可变参数函数。 字符都提升到 INT 浮动提升为双击

The reason for this is that early versions of C did not have function prototypes; parameter types were declared at the function site but were not known at the call site. But different types are represented differently, and the representation of the passed argument must match the called function's expectation. So that char and short values could be passed to functions with int parameters, or float values could be passed to functions with double parameters, the compiler "promoted" the smaller types to be of the larger type. This behavior is still seen when the type of the parameter is not known at the call site -- namely, for variadic functions or functions declared without a prototype (e.g., int foo();).

这篇关于可变参数函数(在va_arg)不使用float工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:29