Tag: 说明书

是否有一个printf说明符要求浮点数不是双倍?

当我使用带有float类型参数的snprintf “%f”说明符时,我得到MISRA类型错误。 根据我的研究,MISRA是正确的,因为“%f”预示着一种double类型。 是否有浮点说明符或修饰符将使用float类型参数而不是double ? 我正在研究嵌入式系统,并且不想将32位浮点数转换为64位double精度,只是为了取悦snprintf函数。 代码打印到调试/控制台端口,这是转换发生的唯一位置。 对于那些需要代码示例的人: // This section is for those C++ purists and it fulfills the C++ tag. #if __cplusplus #include #else #include #endif #define BUFFER_SIZE (128U) int main(void) { char buffer[BUFFER_SIZE]; float my_float = 1.234F; // The compiler will promote the single precision “my_float” // to double precision before passing […]