如果我给浮标而不是双打,我会收到警告。这就是我使用static_casts加倍的原因。 如果我决定不投射,有没有办法避免编译器警告?为什么会出现此警告?在我的系统(8位处理器)中,我怀疑double甚至与float相同。
printf("{\"type\":\"pid_cnf\","
"\"pit_rkp\":%.2f,\"pit_rki\":%.2f,\"pit_rimax\":%.2f,"
"\"rol_rkp\":%.2f,\"rol_rki\":%.2f,\"rol_rimax\":%.2f,"
"\"yaw_rkp\":%.2f,\"yaw_rki\":%.2f,\"yaw_rimax\":%.2f,"
"\"pit_skp\":%.2f,\"rol_skp\":%.2f,\"yaw_skp\":%.2f}\n",
static_cast<double>(pit_rkp), static_cast<double>(pit_rki), static_cast<double>(pit_rimax),
static_cast<double>(rol_rkp), static_cast<double>(rol_rki), static_cast<double>(rol_rimax),
static_cast<double>(yaw_rkp), static_cast<double>(yaw_rki), static_cast<double>(yaw_rimax),
static_cast<double>(pit_skp), static_cast<double>(rol_skp), static_cast<double>(yaw_skp) );
答案 0 :(得分:0)
您收到警告是因为您调用了一个可变参数函数(printf()
),该函数需要参数提升(short
s到int
s,float
s到{{ 1}} s等。)