我的代码中有以下功能:
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’
我对导致这种情况的原因感到茫然......有什么想法吗?
答案 0 :(得分:14)
您需要加入math.h
答案 1 :(得分:1)
根据警告的措辞,您似乎正在使用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'