Question

I get warning if I give floats instead of doubles. This is why I use static_casts to double. Is there a way to avoid compiler warnings if I decide not to cast? Why is this warning existing? In my system (8 bit processor) I doubt double is even of the same size as 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) );
Était-ce utile?

La solution

You get a warning because you call a variadic function (printf()) which is subject to parameter promotion (shorts to ints, floats to doubles, etc.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top