函数声明和花括号之间的C语句 [英] C statement between function declaration and curly brace
问题描述
Possible Duplicate:
What is useful about this C syntax?
C variable declarations after function heading in definition
What weird C syntax is this?
我正在尝试理解一些代码,它具有如下所示的内容:
I'm trying to understand some code and it has something like the following:
int getr(fget)
FILE *fget;
{
/* More declarations and statements here */
return (1);
}
以上内容和以下内容之间是否有任何区别?
Is there any difference between the above and:
int getr(fget)
{
FILE *fget;
/* More declarations and statements here */
return (1);
}
如果是这样,它们有何不同?
If so, how do they differ?
推荐答案
两个函数均以旧式(非原型)形式声明.旧式函数声明在当前的C标准中已过时,C标准强烈建议不要使用它们.
Both functions are declared in the old-style (non-prototype) form. Old-style function declarations are obsolescent in the current C standard and their use is strongly discouraged by the C Standard.
在第二种形式中,没有提及被假定为int
的fget
参数类型.然后,声明另一个类型为FILE *
的对象fget
,它用相同的名称遮盖了参数变量.
In the second form there is no mention of the fget
parameter type which is assumed to be an int
. Then another object fget
of type FILE *
is declared and it shadows the parameter variable with the same name.
使用gcc
时,由于参数的阴影,使用-Wshadow
警告选项将在第二个示例中向您发出警告:
With gcc
the -Wshadow
warning option would get you a warning in your second example because of the shadowing of the parameter:
-Wshadow
Warn whenever a local variable shadows another local variable,
parameter or global variable or whenever a built-in function is shadowed.
这篇关于函数声明和花括号之间的C语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!