函数声明和花括号之间的C语句 [英] C statement between function declaration and curly brace

查看:117
本文介绍了函数声明和花括号之间的C语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
此C语法有什么用?
定义了函数标题后的C变量声明
这是什么奇怪的C语法?

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.

在第二种形式中,没有提及被假定为intfget参数类型.然后,声明另一个类型为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆