如何删除 C 中的警告?
How to remove warnings in C?
我用 C 编写程序,它没有显示任何错误,但它有一些警告,我不知道如何修复。
第一份工作是
printf uses %d and expects int argument but pos is long int.
printf("Kernel load error: kernel %s is smaller then 11000 bytes. %d bytes loaded total.\n",files[count].name,pos);
第二个是
implicit declaration of function 'mkdir' [-Wimplicit-function-declaration]|
mkdir("kernels");
类似问题,缩短为:
char * path = "kernels";
buildKernels(&path, files, count, &binariesSizeTotal);
实施:
bool buildKernels(char ** path,FILES * files, int count ){
strlen(path);
...
}
built-in 函数 'strlen' 的隐式声明不兼容 [默认启用]|
还有两个:
*implicit declaration of function 'buildKernels' [-Wimplicit-function-declaration]|
implicit declaration of function 'loadKernels' [-Wimplicit-function-declaration]|*
两个函数都在 headers 中声明。我不确定“隐式声明”是什么意思。编译器对我有什么期望?如何修复这些错误?
最后一个我没有成功解决的问题:
while( token != NULL )
{
printf( " %s\n", token );
token = strtok(NULL, s); // char *strtok(char *str, const char *delim)
}
这给了我警告警告:
comparison between pointer and integer [enabled by default]|
对变量 pos
使用格式说明符 %ld
。
在声明函数 mkdir
和 buildKernels
的地方包含 headers,或者至少在它们的调用之前包含它们的声明。
还要考虑函数 buildKernels
是用四个参数
调用的
char * path = "kernels";
buildKernels(&path, files, count, &binariesSizeTotal);
但贴标了三个参数
bool buildKernels(char ** path,FILES * files, int count ){
...
}
所以这可能是错误的原因。
函数strlen
。当您传递 char **
类型的参数时,需要一个 const char *
类型的参数
bool buildKernels(char ** path,FILES * files, int count ){
strlen(path);
将参数 path
声明为类型 char *
或正确调用函数 strlen
,如
strlen( *path );
至于最后一个警告,如果令牌是指针,则代码有效。您应该显示完整的警告消息。或者 NULL 可能是以 C++ 风格而不是 C 风格定义的。你不应该自己定义 NULL。
我用 C 编写程序,它没有显示任何错误,但它有一些警告,我不知道如何修复。
第一份工作是
printf uses %d and expects int argument but pos is long int.
printf("Kernel load error: kernel %s is smaller then 11000 bytes. %d bytes loaded total.\n",files[count].name,pos);
第二个是
implicit declaration of function 'mkdir' [-Wimplicit-function-declaration]|
mkdir("kernels");
类似问题,缩短为:
char * path = "kernels";
buildKernels(&path, files, count, &binariesSizeTotal);
实施:
bool buildKernels(char ** path,FILES * files, int count ){
strlen(path);
...
}
built-in 函数 'strlen' 的隐式声明不兼容 [默认启用]|
还有两个:
*implicit declaration of function 'buildKernels' [-Wimplicit-function-declaration]|
implicit declaration of function 'loadKernels' [-Wimplicit-function-declaration]|*
两个函数都在 headers 中声明。我不确定“隐式声明”是什么意思。编译器对我有什么期望?如何修复这些错误?
最后一个我没有成功解决的问题:
while( token != NULL )
{
printf( " %s\n", token );
token = strtok(NULL, s); // char *strtok(char *str, const char *delim)
}
这给了我警告警告:
comparison between pointer and integer [enabled by default]|
对变量 pos
使用格式说明符 %ld
。
在声明函数 mkdir
和 buildKernels
的地方包含 headers,或者至少在它们的调用之前包含它们的声明。
还要考虑函数 buildKernels
是用四个参数
char * path = "kernels";
buildKernels(&path, files, count, &binariesSizeTotal);
但贴标了三个参数
bool buildKernels(char ** path,FILES * files, int count ){
...
}
所以这可能是错误的原因。
函数strlen
。当您传递 char **
const char *
类型的参数
bool buildKernels(char ** path,FILES * files, int count ){
strlen(path);
将参数 path
声明为类型 char *
或正确调用函数 strlen
,如
strlen( *path );
至于最后一个警告,如果令牌是指针,则代码有效。您应该显示完整的警告消息。或者 NULL 可能是以 C++ 风格而不是 C 风格定义的。你不应该自己定义 NULL。