功能和主要 [英] functions and main

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

问题描述

以下编程仅在原型

(< - 形容词)定义相对于主调用的位置上有所不同。构建和

都适合我。一旦

主题变得更加棘手,是否存在差异? MPJ

#include< stdio.h>

int main(无效){

int i = 5;

void increment(int *);

increment(& i);

printf(" i =%d \ n",i);

返回0;

}

void increment(int * px){

int tmp = * px;

++ tmp;

* px = tmp;

}

#include< stdio.h>

void increment(int *);

int main(void){

int i = 5;

increment( & i);

printf(" i =%d \ n",i);

返回0;

}

void increment(int * px){

int tmp = * px;

++ tmp;

* px = tmp;

}

The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ
#include <stdio.h>
int main(void){
int i = 5;
void increment(int *);
increment(&i);
printf("i = %d\n",i);
return 0;
}
void increment(int *px){
int tmp = *px;
++ tmp;
*px = tmp;
}
#include <stdio.h>
void increment(int *);
int main(void){
int i = 5;
increment(&i);
printf("i = %d\n",i);
return 0;
}
void increment(int *px){
int tmp = *px;
++ tmp;
*px = tmp;
}

推荐答案

2004年11月17日星期三06:38:56 -0600,Merrill& ; Michele写道:
On Wed, 17 Nov 2004 06:38:56 -0600, Merrill & Michele wrote:
以下编程仅在原型
(< - 形容词)定义相对于主调用的位置上有所不同。构建和
都适合我。一旦
主题变得更加棘手,是否存在差异? MPJ
The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ




是的,这是将函数声明放在

a函数(即块作用域)或函数外部(即在档案

范围)。不要在函数中放置函数声明,如果你这样做,那么
编译器永远不需要验证函数定义的声明类型(无论如何可能但是它不是必须的)。它也不是C程序员期望找到它们的地方。如果你遵守规则,你就不会错误




1.静态函数声明应该在文件的顶部或附近

定义了函数。有些人喜欢在

使用前放置定义,以避免需要声明。这也很好,虽然我喜欢

将声明作为源文件中函数的摘要。


2.非静态函数声明应该在一个适当的标题中。

文件包含在使用该函数的所有源文件中。


劳伦斯



Yes, this is the difference between putting a function declaration in
a function (i.e. at block scope) or outside a function (i.e. at file
scope). Don''t put function declarations in functions, if you do the
compiler is never required to validate the type of the declaration against
the function definition (it might anyway but it isn''t required to). It is
also not where C programmers expect to find them. You won''t go far wrong
if you stick to the rules

1. A static function declaration should go at or near the top of the file
where the function is defined. Some people prefer to put definition before
use to avoid the need for a declaration. That''s fine too, although I like
having the declarations as a summary of the functions in the source file.

2. A non-static function declaration should be in an appropriate header
file that is included by all source files that use the function.

Lawrence




" Lawrence Kirby" < LK **** @ netactive.co.uk>在消息中写道

news:pa **************************** @ netactive.co.u k。 ..

"Lawrence Kirby" <lk****@netactive.co.uk> wrote in message
news:pa****************************@netactive.co.u k...
2004年11月17日星期三06:38:56 -0600,Merrill& Michele写道:
On Wed, 17 Nov 2004 06:38:56 -0600, Merrill & Michele wrote:
以下编程仅在原型
(< - 形容词)定义相对于主调用的位置上有所不同。构建和
都适合我。一旦
主题变得更加棘手,是否存在差异? MPJ
The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ



是的,这是将函数声明放在函数(即块作用域)或函数外(即文件
范围)之间的区别)。不要在函数中放置函数声明,如果你这样做,
编译器永远不需要验证函数定义的声明类型(它可能无论如何但它不是必须的) 。它也不是C程序员期望找到它们的地方。如果你遵守规则,你就不会错误























定义。有些人喜欢在使用之前使用定义来避免需要声明。这也没关系,虽然我喜欢
将声明作为源文件中函数的摘要。

2.非静态函数声明应该在适当的头文件中
使用该函数的所有源文件包含的文件。



Yes, this is the difference between putting a function declaration in
a function (i.e. at block scope) or outside a function (i.e. at file
scope). Don''t put function declarations in functions, if you do the
compiler is never required to validate the type of the declaration against
the function definition (it might anyway but it isn''t required to). It is
also not where C programmers expect to find them. You won''t go far wrong
if you stick to the rules

1. A static function declaration should go at or near the top of the file
where the function is defined. Some people prefer to put definition before
use to avoid the need for a declaration. That''s fine too, although I like
having the declarations as a summary of the functions in the source file.

2. A non-static function declaration should be in an appropriate header
file that is included by all source files that use the function.



谢谢。我刚刚违反了波普先生的禁令,要求顺便通过K& R
并且正在翻阅C Unleashed。我向Summit先生道歉,打印了他的常见问题解答并绑定了他的常见问题解答而没有给他一分钱,而我却没有意识到我确实拥有了b $ b。有一个问题我一直想要问:什么

到底有什么''foo''代表什么? MPJ


Thanks. I just violated Mr. Pop''s injunction to go through K&R sequentially
and was leafing through C Unleashed. I had apologized to Mr. Summit for
printing off and binding his FAQs without giving him a cent while unaware
that I indeed had. There is a question I''ve been dying to ask though: what
the hell does ''foo'' stand for? MPJ




" Merrill&米歇尔" <是******** @ comcast.net>在留言中写道

news:r _ ******************** @ comcast.com ...

"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
那里这是一个我一直想要问的问题:什么是什么?'foo'代表什么? MPJ
There is a question I''ve been dying to ask though: what
the hell does ''foo'' stand for? MPJ




这是一个由程序员经常光顾的热门咖啡馆的名字:Foo Bar,由Foo先生拥有
。 />



It''s the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.


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

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