C怀疑 [英] C doubts

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

问题描述

1)任何人都可以举一个C程序的例子,只能用goto写成
吗?即一个我们无法避免关键字的程序

goto


2)tmpfile()的目的究竟是什么?它会打开一个临时的

文件吗?


3)为什么FAQ中没有关于悬空指针的文章?

1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?

3)why there is no article on dangling pointer in the FAQ ?

推荐答案

文章

< 59 ************************* ********* @ e10g2000prf。 googlegroups.com>,
所以********** @ gmail.com < so ********** @ gmail.comwrote周四15

2007年11月11:52 pm:
In article
<59**********************************@e10g2000prf. googlegroups.com>,
so**********@gmail.com <so**********@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:

1)任何人都可以举一个C程序的例子,只能用goto写成
吗?即我们无法避免关键字的程序

转到
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto



如果有这样的程序,它可能会被设计。大多数现实世界

程序可以在必要时避免使用goto,尽管大多数*使用

吧。

If there is such a program it''s likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.


2)tmpfile()的目的究竟是什么?它会打开一个临时的

文件吗?
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?



是的。它返回一个指向流的指针,该流将有效,直到通过fclose()或正常的程序终止来关闭


Yes. It returns a pointer to a stream which will be valid until it is
closed via fclose() or by normal program termination.


3 )为什么在常见问题解答中没有关于悬空指针的文章?
3)why there is no article on dangling pointer in the FAQ ?



见问题7.1

See question 7.1


11月15日下午1:38,santosh< santosh .... @ gmail.comwrote:
On Nov 15, 1:38 pm, santosh <santosh....@gmail.comwrote:

文章

< 59873ca2-b9a9-4e2a-87a9-4d0cc4844 ... @ e10g2000prf.googlegroups.com>,

sophia.ag ... @ gmail.com< sophia.ag ... @ gmail.comwrote周四15

11月2007年下午11:52:
In article
<59873ca2-b9a9-4e2a-87a9-4d0cc4844...@e10g2000prf.googlegroups.com>,
sophia.ag...@gmail.com <sophia.ag...@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:

1)任何人都可以举一个C程序的例子,只能用goto写成
?即一个程序,我们无法避免关键字

转到
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto



如果有这样的程序,它可能会被设计。大多数现实世界

程序可以在必要时避免使用goto,尽管大多数*使用

吧。


If there is such a program it''s likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.


2)tmpfile()的目的究竟是什么?它会打开一个临时的

文件吗?
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?



是的。它返回一个指向流的指针,该流将有效,直到通过fclose()或正常的程序终止来关闭



Yes. It returns a pointer to a stream which will be valid until it is
closed via fclose() or by normal program termination.


3 )为什么在常见问题解答中没有关于悬空指针的文章?
3)why there is no article on dangling pointer in the FAQ ?



见问题7.1


See question 7.1



问题7.1指向此链接: -
http://c-faq.com/malloc/malloc1.html

不是吗?


但它没有说悬挂指针的任何事情

Question 7.1 points to this link:-
http://c-faq.com/malloc/malloc1.html
is n''t it?

but it does n''t say any thing about dangling pointer


jacob navia写道,在15/11/07 19:07:
jacob navia wrote, On 15/11/07 19:07:
所以********** @ gmail.com 写道:

> 1)任何人都可以给出一个例子对于只能使用goto编写的C程序?即我们无法避免关键字的程序
goto
>1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto



此代码片段演示:


开关(整数){

案例534:

switch(n){

案例254:

goto goon;

案例566:

//

休息;

}

printf( 未找到534的子项目;

休息;

}

返回0;

goon:

返回6445;

}


显然*可以*重新排列


This code snippet demonstrates that:

switch (integer) {
case 534:
switch (n) {
case 254:
goto goon;
case 566:
//
break;
}
printf("Sub-item for 534 not found");
break;
}
return 0;
goon:
return 6445;
}

Obviously that *could* be rearranged



很容易,所以它不是一个证明你的观点的例子。

Very easily, so it is not an example that demonstrates your point.


但重点是语言

不提供命名休息声明。如果你想打破

嵌套开关,嵌套循环或嵌套结构,你需要

来使用goto语句
but the point is that the language
does not provide a "named" break statement. If you want to break from
nested switches, nested loops, or nested constructs like that you have
to use the goto statement



或者是一面旗帜,或者有时你可以通过使用另一层功能

和一个返回来做到这一点,或者......


我相信C仍然是Turing完全没有goto,即

不是需要goto的程序。但是,这并不意味着

建议避免使用goto只是为了避免使用

goto。


< snip>

-

Flash Gordon

Or a flag, or sometimes you can do it by using another layer of function
and a return, or...

I believe that C would still be Turing complete without goto, i.e. there
are no programs for which goto is required. However, that does not mean
it is advisable to avoid using goto just for the sake of avoiding using
goto.

<snip>
--
Flash Gordon


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

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