12

I have the following function in my code:

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;
    }
}

At compile time I get the following warning:

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’

I'm at a loss for what is causing this... any ideas?

Ian Burris
  • 6,325
  • 21
  • 59
  • 80

2 Answers2

18

You need to include math.h

And why exactly do we get this warning?

Community
  • 1
  • 1
codaddict
  • 445,704
  • 82
  • 492
  • 529
2

From the wording of your warnings it looks like you are using gcc? Maybe it is worth to try another compiler, namely clang. This one tells me:

 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'
Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177