原型 [英] Prototypes

查看:93
本文介绍了原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C语言是否要求您使用原型函数?如果不是需要
,是否建议使用?

Does the C language require you to prototype functions? If it''s not
required, is it recommended?

推荐答案

9月2日星期二2003 07:26:40 GMT,fb< me@no.net>在comp.lang.c中写道:
On Tue, 02 Sep 2003 07:26:40 GMT, fb <me@no.net> wrote in comp.lang.c:
C语言是否要求您使用原型函数?如果不需要,是推荐吗?
Does the C language require you to prototype functions? If it''s not
required, is it recommended?




IMNSHO,有史以来对C语言的最大改进

是原型的添加。 推荐一词甚至没有
接近描述正确使用的原型在

中的影响,大大减少了编码错误。任何名副其实的专业组织

的名称肯定需要编程员工生产

并使用足够的原型。


至于要求根据语言,有一些情况下它不是b $ b。


如果一个函数返回一个int,没有一个变量参数列表,

及其所有参数都有一个默认参数支持的类型

促销,那么在原型范围内拥有原型

不是语言要求。


根据最新版本的C标准,目前编译器中没有太广泛实现

,它至少需要声明

甚至那些不需要原型的功能。


-

Jack Klein

主页: http://JK-Technology.Com



comp.lang.c的常见问题解答 http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http:// www .parashift.com / c ++ - faq-lite /

alt.comp.lang.learn.c-c ++ ftp://snurse-l.org/pub/acllc-c++/faq



IMNSHO, the single greatest improvement ever made to the C language
was the addition of prototypes. The word "recommended" does not even
come close to describing the impact of properly used prototypes in
greatly reducing coding errors. Any professional organization worthy
of the name will certainly require programming employees to produce
and use adequate prototypes.

As for required by the language, there are a few cases where it is
not.

If a function returns an int, does not have a variable argument list,
and all its arguments have a type supported by the default argument
promotions, then it is not a language requirement to have a prototype
in scope.

Under the latest version of the C standard, not too widely implemented
in compilers as of yet, it is required to have at least a declaration
of even those functions that are not required to have prototypes.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

Jack Klein写道:
Jack Klein wrote:
On Tue,02 Sep 2003 07:26:40 GMT,fb< me@no.net>在comp.lang.c中写道:

On Tue, 02 Sep 2003 07:26:40 GMT, fb <me@no.net> wrote in comp.lang.c:

C语言是否要求您使用原型函数?如果不需要,是推荐吗?
Does the C language require you to prototype functions? If it''s not
required, is it recommended?



IMNSHO,对C语言进行的最大改进是原型的添加。 推荐一词甚至没有接近描述正确使用原型的影响,大大减少了编码错误。任何名副其实的专业组织肯定都需要编程员工来制作
并使用足够的原型。

至于语言的要求,有几个案例是
不是。

如果一个函数返回一个int,没有一个变量参数列表,
及其所有参数都有一个默认参数支持的类型
促销,那么在原型范围内使用原型并不是语言要求。

根据最新版本的C标准,在编译器中尚未广泛实现
,它至少需要声明那些不需要原型的功能。


IMNSHO, the single greatest improvement ever made to the C language
was the addition of prototypes. The word "recommended" does not even
come close to describing the impact of properly used prototypes in
greatly reducing coding errors. Any professional organization worthy
of the name will certainly require programming employees to produce
and use adequate prototypes.

As for required by the language, there are a few cases where it is
not.

If a function returns an int, does not have a variable argument list,
and all its arguments have a type supported by the default argument
promotions, then it is not a language requirement to have a prototype
in scope.

Under the latest version of the C standard, not too widely implemented
in compilers as of yet, it is required to have at least a declaration
of even those functions that are not required to have prototypes.



Ok ...很酷。

因此,如果我想要原型,我会做类似的事情:


#include< stdio.h>


int cube(int c ); /* 这是正确的吗? * /


int main(无效)

{

int x = 10,y = 7;

int v;

printf(" X =%d \ n",x);

v = cube(x);

printf(" Now X =%d \ n \ nn,",v);

printf(" Y =%d \ nn,y);

v = cube(y);

printf(" Now Y =%d\\\
\ n,v);

返回0; < br $>
}

int cube(int c)

{

return(c * c * c);

}


正确吗?


Ok...Cool.
So if I want to prototype I would do something like:

#include <stdio.h>

int cube(int c); /* Is this right? */

int main(void)
{
int x = 10, y = 7;
int v;
printf("X = %d\n",x);
v = cube(x);
printf("Now X = %d\n\n",v);
printf("Y = %d\n",y);
v = cube(y);
printf("Now Y = %d\n\n",v);
return 0;
}
int cube(int c)
{
return (c*c*c);
}

Correct?


fb< me@no.net>写在

< HF *********************** @ news2.calgary.shaw.ca>:
fb <me@no.net> wrote in
<HF***********************@news2.calgary.shaw.ca >:
Jack Klein写道:
< SNIP>
Jack Klein wrote: <SNIP>
根据最新版本的C标准,没有太广泛实施
在编译器中,它至少需要有一个声明,甚至是那些不需要原型的函数。
Under the latest version of the C standard, not too widely implemented
in compilers as of yet, it is required to have at least a declaration
of even those functions that are not required to have prototypes.


好的......很酷。
所以如果我想要原型,我会做类似的事情:

< stdio.h>

int cube(int c); /* 这是正确的吗? * /


Ok...Cool.
So if I want to prototype I would do something like:

#include <stdio.h>

int cube(int c); /* Is this right? */



对。在一个稍微大一点的项目中,你想将

这个放在头文件中。

int main(void)
{
int x = 10 ,y = 7;
int v;
printf(" X =%d \ n",x);
v = cube(x);
printf(" ;现在X =%d \ n \ n",v);
printf(Y =%d \ n,y);
v = cube(y);
printf(" Now Y =%d\\\
\ n",v);
返回0;
}
int cube(int c)
{
返回(c * c * c);
}

正确吗?


Right. In a somewhat larger project you would like to put
this in a header file.

int main(void)
{
int x = 10, y = 7;
int v;
printf("X = %d\n",x);
v = cube(x);
printf("Now X = %d\n\n",v);
printf("Y = %d\n",y);
v = cube(y);
printf("Now Y = %d\n\n",v);
return 0;
}
int cube(int c)
{
return (c*c*c);
}

Correct?



正确。


Irrwahn

-

空气是带水洞的水。


Correct.

Irrwahn
--
Air is water with holes in it.


这篇关于原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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