C语言 stderr 未声明的标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15289613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
stderr undeclared identifier
提问by Capricorn
void
argmatch_valid (const char *const *arglist,
const char *vallist, size_t valsize)
{
size_t i;
const char *last_val = NULL;
fprintf (stderr, _("Valid arguments are:"));
for (i = 0; arglist[i]; i++)
if ((i == 0)|| memcmp (last_val, vallist + valsize * i, valsize))
{
fprintf (stderr, "\n - `%s'", arglist[i]);
last_val = vallist + valsize * i;
}
else
{
fprintf (stderr, ", `%s'", arglist[i]);
}
putc ('\n', stderr);
}
I am getting the following although I have included stdio.h in my .c file
尽管我在 .c 文件中包含了 stdio.h,但我得到以下信息
warning C4013: 'fprintf' undefined; assuming extern returning int error C2065: 'stderr' : undeclared identifier warning C4013: 'putc' undefined; assuming extern returning int
I thought of disabling the warning by #pragma warning( disable :4013 ) but wanted to compile the code clean.
我想通过 #pragma warning( disable :4013 ) 禁用警告,但想编译干净的代码。
Thanks in advance
提前致谢
回答by selbie
While stdio.h should work, sometimes you need to include stdlib.h as well. Include the following:
虽然 stdio.h 应该可以工作,但有时您还需要包含 stdlib.h。包括以下这些:
#include <stdio.h>
#include <stdlib.h>
Declare both of these includes at the TOP of the same.C file your argmatch_valid function above is defined.
在上面定义的 argmatch_valid 函数的同一个.C 文件的顶部声明这两个包含。
My crystal ball suggests that the stdio.h you think you are including is getting wrapped by a comment or within another preprocessor section that is getting wiped out. Maybe you can post your entire source file. Someone will likely spot the real error.
我的水晶球表明您认为包含的 stdio.h 正在被评论包裹或在另一个正在消失的预处理器部分中。也许您可以发布整个源文件。有人可能会发现真正的错误。

