C语言函数声明中参数类型写在右括号后是什么意思?

yuanjie_xia 2012-11-01 11:52:32
int add(a, b)
int a;
int b;
{
return a + b;
}

像这样的声明是什么意思,我测试过在gcc和vc++里都能通过,但就是不明白是什么意思,有什么用处?哪里有说明文档?
...全文
2303 30 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryfdizuo 2013-08-20
  • 打赏
  • 举报
回复
c和指针上有介绍
pengfangxu8 2013-08-20
  • 打赏
  • 举报
回复
这个是老东西了。
陌上_桑 2013-08-20
  • 打赏
  • 举报
回复
第一次见这种写法
nextseconds 2013-08-19
  • 打赏
  • 举报
回复
过时了的C语法
艾薇儿More 2013-08-16
  • 打赏
  • 举报
回复
c专家编程上有
shiguojie19892 2013-08-16
  • 打赏
  • 举报
回复
长知识了,没有见过,我认为应该是标准c里面的,一直兼容下来了,现在有了简化的写法。就好比繁体字和简体字,功能一样,只是复杂度不一样。
yuanpengguo1314 2013-08-15
  • 打赏
  • 举报
回复
见识了。。。。
忘世麒麟 2013-08-15
  • 打赏
  • 举报
回复
没人用这个.除非喜欢特立独行.没有哪家公司的编码规范会要求你这样写.了解即可.
Nikomememe 2013-08-15
  • 打赏
  • 举报
回复
引用 1 楼 lin5161678 的回复:
古老的写法 和 int add(int a, int b) 这个是一样的
+1
wuwusansan 2013-08-15
  • 打赏
  • 举报
回复
哦,这个形式不要了,
赵4老师 2013-08-15
  • 打赏
  • 举报
回复
C Function Definitions A function definition specifies the name of the function, the types and number of parameters it expects to receive, and its return type. A function definition also includes a function body with the declarations of its local variables, and the statements that determine what the function does. Syntax translation-unit : external-declaration translation-unit external-declaration external-declaration : /* Allowed only at external (file) scope */ function-definition declaration function-definition : /* Declarator here is the function declarator */ declaration-specifiersopt attribute-seqopt declarator declaration-listopt compound-statement /* attribute-seq is Microsoft Specific */ Prototype parameters are: declaration-specifiers : storage-class-specifier declaration-specifiers opt type-specifier declaration-specifiers opt type-qualifier declaration-specifiers opt declaration-list : declaration declaration-list declaration declarator : pointeropt direct-declarator direct-declarator : /* A function declarator */ direct-declarator ( parameter-type-list ) /* New-style declarator */ direct-declarator ( identifier-list opt ) /* Obsolete-style declarator */ The parameter list in a definition uses this syntax: parameter-type-list : /* The parameter list */ parameter-list parameter-list , ... parameter-list : parameter-declaration parameter-list , parameter-declaration parameter-declaration : declaration-specifiers declarator declaration-specifiers abstract-declarator opt The parameter list in an old-style function definition uses this syntax: identifier-list : /* Used in obsolete-style function definitions and declarations */ identifier identifier-list , identifier The syntax for the function body is: compound-statement : /* The function body */ { declaration-list opt statement-list opt } The only storage-class specifiers that can modify a function declaration are extern and static. The extern specifier signifies that the function can be referenced from other files; that is, the function name is exported to the linker. The static specifier signifies that the function cannot be referenced from other files; that is, the name is not exported by the linker. If no storage class appears in a function definition, extern is assumed. In any case, the function is always visible from the definition point to the end of the file. The optional declaration-specifiers and mandatory declarator together specify the function’s return type and name. The declarator is a combination of the identifier that names the function and the parentheses following the function name. The optional attribute-seq nonterminal is a Microsoft-specific feature defined in Function Attributes. The direct-declarator (in the declarator syntax) specifies the name of the function being defined and the identifiers of its parameters. If the direct-declarator includes a parameter-type-list, the list specifies the types of all the parameters. Such a declarator also serves as a function prototype for later calls to the function. A declaration in the declaration-list in function definitions cannot contain a storage-class-specifier other than register. The type-specifier in the declaration-specifiers syntax can be omitted only if the register storage class is specified for a value of int type. The compound-statement is the function body containing local variable declarations, references to externally declared items, and statements. The sections Function Attributes, Storage Class, Return Type, Parameters, and Function Body describe the components of the function definition in detail.
mujiok2003 2013-08-14
  • 打赏
  • 举报
回复
这种代码还可以在linux 源码中找到,老的语法。考虑兼容性,保留至今。
  • 打赏
  • 举报
回复
我以前在IBM实习的时候LSF组的很多老外写的代码就是这样子的,很古老
wizard_tiger 2012-11-05
  • 打赏
  • 举报
回复
这个是老语法了,建议楼主不要写成这个样子。
liangsheniscoming 2012-11-05
  • 打赏
  • 举报
回复
ANSI C标准之前的形式,已废弃。
JiMoKuangXiangQu 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
int add(a, b)
int a;
int b;
{
return a + b;
}

像这样的声明是什么意思,我测试过在gcc和vc++里都能通过,但就是不明白是什么意思,有什么用处?哪里有说明文档?
[/Quote]

建议不要再使用这种K&R风格.
lin5161678 2012-11-01
  • 打赏
  • 举报
回复
古老的写法
和 int add(int a, int b)
这个是一样的
startservice 2012-11-01
  • 打赏
  • 举报
回复
vs2008不支持。
weidu23 2012-11-01
  • 打赏
  • 举报
回复
这种写法是正确的,
还受到 ANSI C标准的认可。
======
我第一次了解到这种写法是在Andrew Koenig的书里。

这段代码,相当于:
int add ( int a, int b )
{
return a+b;
}
sergery 2012-11-01
  • 打赏
  • 举报
回复
都怪语法太灵活了.
计算机语言的语法就应该严格规定一种写法.
否则是浪费大家的时间.
加载更多回复(9)

70,026

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧