c++ - 使用 GCC 或/和 IAR 编译时如何禁用 double 学?

标签 c++ c gcc embedded arm

我的嵌入式 C 代码在具有单精度 FPUCortex M4F 上运行。我担心编译器多久将基于软件的 double 学放在诸如

**

float_var1 = 3.0 * int_var / float_var_2;
(3.0 instead of 3.0f)

**

我担心我会错过其中一些双常数。我怎样才能找到所有出现的较慢的 double 学?使用 sourcery GCC 或 IAR 禁用 double 或生成错误/警告即可。

请指导我实现目标的正确方法。

最佳答案

How can I locate all occurrences of slower double-precision math? Disabling double-precision or generating an error/warning with either sourcery GCC or IAR would do it.

-Wdouble-promotion 完全符合您的要求,请参阅 Warning Options 下的文档.顺便说一句,文档中的示例与您的非常相似。

这基本上是你的例子:

float f(int int_var, float float_var_2) {
  return 3.0 * int_var / float_var_2;
}

下面是我将 -Wdouble-promotion 标志传递给 gcc 时发生的情况:

gcc -c -Wdouble-promotion float.c
float.c: In function ‘f’:
float.c:2:24: warning: implicit conversion from ‘float’ to ‘double’ to match other operand of binary expression [-Wdouble-promotion]

如果您也传递了 -Werror 标志,您可以将所有警告变成错误。如果这太严格,您可以通过传递 -Werror=foo 有选择地将警告转换为错误,请参阅 Warning Options 下的文档

关于c++ - 使用 GCC 或/和 IAR 编译时如何禁用 double 学?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24348227/

相关文章:

c++ - 读取较大文件时出现未处理的异常

c - 使用二分法求方程的根

c - GCC 4.4.3 中的功能特定优化

C++ 映射将所有键的值显示为 0

c++ - 'snapshot' 函数是什么?

c - 无法链接到 libgfortran.a

c - 指针转换期间运行时的 EXC_BAD_ACESS

gcc - 基于ARM的嵌入式Linux系统的交叉编译

c - 避免在头文件中为弱引用重新定义别名变量

c++ - O(N) 算法比 O(N logN) 算法慢