【问题标题】:Getting warning from C math library's pow function从 C 数学库的 pow 函数中获取警告
【发布时间】:2010-09-20 03:29:43
【问题描述】:

我的代码中有以下函数:

int numberOverflow(int bit_count, int num, int twos) {
    int min, max;
    if (twos) {
        min = (int) -pow(2, bit_count - 1);        \\ line 145
        max = (int) pow(2, bit_count - 1) - 1;
    } else {
        min = 0;
        max = (int) pow(2, bit_count) - 1;         \\ line 149
    }
    if (num > max && num < min) {
        printf("The number %d is too large for it's destination (%d-bit)\n", num, bit_count);
        return 1;
    } else {
        return 0;
    }
}

在编译时我收到以下警告:

assemble.c: In function ‘numberOverflow’:
assemble.c:145: warning: incompatible implicit declaration of built-in function ‘pow’
assemble.c:149: warning: incompatible implicit declaration of built-in function ‘pow’

我不知道是什么原因造成的……有什么想法吗?

【问题讨论】:

    标签: c math warnings compiler-warnings


    【解决方案1】:

    您需要包含math.h

    还有why exactly do we get this warning?

    【讨论】:

    • 呸...我怎么忘了这样做?谢谢。
    【解决方案2】:

    从您的警告措辞看来,您使用的是gcc?也许值得尝试另一个编译器,即clang。这个告诉我:

     test-pow.c:15:18: warning: implicitly declaring C library function 'pow' with type 'double (double, double)' [-pedantic]
     test-pow.c:15:18: note: please include the header <math.h> or explicitly provide a declaration for 'pow'
    

    【讨论】:

      猜你喜欢
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 2023-04-04
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多