2010-09-20 27 views
9

tôi có chức năng sau trong mã của tôi:Bắt cảnh báo từ chức năng pow C thư viện toán học của

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

Tại thời gian biên dịch tôi nhận được cảnh báo sau đây:

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’ 

Tôi đang ở một mất mát cho điều gì đang gây ra điều này ... bất kỳ ý tưởng nào?

Trả lời

1

Từ cách diễn đạt các cảnh báo của bạn có vẻ như bạn đang sử dụng gcc? Có lẽ nó là giá trị để thử một trình biên dịch, cụ thể là clang. Điều này cho tôi biết:

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' 
Các vấn đề liên quan