我知道这经常被问到,但我阅读了十几个问题但仍未找到解决方案。编译时我收到警告:
warning: assignment makes pointer from integer without a cast
此警告所指的代码为:
unsigned char *WebPrintReturnLine(BIO *bio) {
long int i;
unsigned int turn = 0;
unsigned char *ptr = 0;
int size;
unsigned char buffer[4096];
i = (long int) WebRead(bio, buffer, sizeof(buffer));
if( (ptr = (unsigned char *) malloc(strlen(buffer))) == 0 ) {
printf("Error: Couldn't allocate memory in WebPrintReturnLine\n");
return ptr;
}
//strlen does not care about '\0' but as array begin at 0 it nulifies
size = strlen(buffer);
//strcpy the buffer into the allocated memory
strcpy(ptr, buffer);
printf("%d\n", isend(buffer, sizeof(buffer)));
while( (i > 0) && (!isend(buffer, sizeof(buffer))) ) {
i = (long int) WebRead(bio, buffer, sizeof(buffer));
size += strlen(buffer);
if( (ptr = (unsigned char*) realloc(ptr, size)) == 0 ) {
printf("Error: Couldn't reallocate memory in WebPrintReturnLine\n");
ptr = 0;
return ptr;
}//End if
//Strcat the original string and the buffer together
strcat(ptr, buffer);
}//End while
//Now finally print the line
printf("%s", ptr);
return ptr;
}
这被称为:
unsigned char *ptr;
if( (ptr = WebPrintReturnLine(bio)) == 0 )
return -1;
我首先要在这个问题中缩短代码,但是我有可能会监督导致此警告的内容。
答案 0 :(得分:0)
因此警告在您问题的第二个代码段中。当您调用它时,WebPrintReturnLine
的声明不可见。在C90规则下,编译器假定它返回int
(在这种情况下不正确)。根据C99规则,电话是非法的。您需要为声明#include
的标头添加WebPrintReturnLine
。 - 基思汤普森