什么是差异b / w“未知”和“未定义的”行为? [英] What is difference b/w "UNSPECIFIED" and "UNDEFINED" behaviour ?

查看:67
本文介绍了什么是差异b / w“未知”和“未定义的”行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我对C来说相对较新(严格来说:好吧我是

学生,并且一直在做和研究C编程的最后4个

年).....还有comp.lang.c的常规读者


我没有ANSI C89标准的副本,因此我不得不发布这个

的问题:


未指定之间的区别是什么?行为与undefined

某些C代码的行为?


提前感谢..


(Nitin )

Well, i''m a relatively new into C( strictly speaking : well i''m a
student and have been doing & studying C programming for the last 4
years).....and also a regular reader of "comp.lang.c"

I don''t have a copy of ANSI C89 standard,therefore i had to post this
question:

What is the difference between "unspecified" behaviour & "undefined"
behaviour of some C Code ??

Thank in advance..

(Nitin)

推荐答案

" Nitin Bhardwaj" < NI ************* @ hotmail.com>在留言中写道

news:17 ************************** @ posting.google.c om ...
"Nitin Bhardwaj" <ni*************@hotmail.com> wrote in message
news:17**************************@posting.google.c om...
好吧,我相对来说是C的新手(严格来说:嗯,我是学生,并且在过去的4年里一直在做和学习C编程).....以及comp.lang.c的常规读者

我没有ANSI C89标准的副本,因此我必须发布此
问题:


它可以在网上以数字格式便宜地购买。最后

Well, i''m a relatively new into C( strictly speaking : well i''m a
student and have been doing & studying C programming for the last 4
years).....and also a regular reader of "comp.lang.c"

I don''t have a copy of ANSI C89 standard,therefore i had to post this
question:

It is available to buy quite cheaply online in digital format. At the last
look


18美元。这是C99标准,尽管当然。如果您查看

网页,应该有一个C9X草案标准浮动。

未指定之间的区别是什么?行为与undefined
某些C代码的行为??
18 USD. That is the C99 standard though ofcourse. If you look on the
web, there should be a C9X draft standard floating about.
What is the difference between "unspecified" behaviour & "undefined"
behaviour of some C Code ??




....


我会有刺伤这些意义,但检查其他后续行动。并且当你在网上找到它时,你需要阅读C9X标准。


无条件:基本上意味着某些事情会特别发生,但是

标准没有说明会是什么 - 而且编译器系统确实没有记录功能。
。例如:

"函数参数的评估顺序是未知。 - 所以

编译器文档没有必要说明它们被评估的顺序。


UNDEFINED:这意味着任何事情都可能发生在这里特别是
案例,其中包括但不限于崩溃,腐败和可能的操作系统或硬件损坏(理论上) - 显然不好的事情如<通常不会发生这种情况,但是它给出了明确的概念,即可能会发生任何事情 - 当然,未完成的行为应该是

在所有C程序中都要避免。


实现 - 定义:这是另一个词,具有明确的含义。它像

一样有缺陷,但这意味着编译器文档*必须*

包含有关特定情况下会发生什么的信息。



....

I will have a stab at these meanings, but check the other follow-ups. And
read the C9X standard when you have found it on the web.

UNSPECIFIED: Essentially means some thing will happen in particular, but the
standard does not say what that thing will be - and the compiler system does
not have to have the feature documented. For example:
"The order of evaluation of function arguments is UNSPECIFIED" - so the
compiler documentation doesn''t have to say in what order they are evaluated.

UNDEFINED: This means that anything whatsoever can happen in this particular
case, which includes, but is not limited to, crashing, corruption, and
potentially OS, or hardware damage(in theory) -- Obviously bad things like
that don''t generally happen, but it gives the express notion that
potentially anything can happen -- and of course UNDEFINED behaviour should
be avoided in all C programs.

IMPLEMENTATION-DEFINED: Here is another word, with a defined meaning. It is
like UNSPECIFIED, but it means that the compiler documentation *must*
include information on what will happen in a particular case.


Nitin Bhardwaj写道:
Nitin Bhardwaj wrote:

好吧,我相对来说很新C(严格来说:嗯,我是学生,并且已经在过去的4年里学习和学习C语言编程.....以及comp.lang.c的常规读者

我没有ANSI C89标准的副本,因此我不得不发布这个问题:

未指定之间的区别是什么?行为与undefined某些C代码的行为??

Well, i''m a relatively new into C( strictly speaking : well i''m a
student and have been doing & studying C programming for the last 4
years).....and also a regular reader of "comp.lang.c"

I don''t have a copy of ANSI C89 standard,therefore i had to post this
question:

What is the difference between "unspecified" behaviour & "undefined"
behaviour of some C Code ??




标准说unspecified.c的输出将是

要么是1 2还是2 1,但它没有说出哪一个,并且它也说

编译器文档也没有;

未指定行为是在行为有限的情况下行为并且行为不需要文件

来指定哪种行为。

/ * BEGIN unspecified.c * /


#include< stdio.h>


int count(int * counter);


int main(无效)

{

int counter = 0;


printf(" %d%d \ n",count(& counter),count(& counter));

返回0;

}


int count(int * counter)

{

返回++ * counter;

}


/ * END unspecified.c * /


如果要删除initialzatio n计数器,

然后行为将是未定义的。

你不知道该程序会做什么。

它甚至可能崩溃。

未定义的行为,是指程序的行为

不在C的规则范围内。


-

pete



The standard says that the output from unspecified.c will be
either 1 2 or 2 1, but it doesn''t say which, and it also says
that compiler documentation doesn''t have to which either;
Unspecified behavior is when there is a limited choice
of behavior and no documentation is required by the implementaion
to specify which behavior.
/* BEGIN unspecified.c */

#include <stdio.h>

int count(int* counter);

int main(void)
{
int counter = 0;

printf("%d %d\n", count(&counter), count(&counter));
return 0;
}

int count(int* counter)
{
return ++*counter;
}

/* END unspecified.c */

If you would remove the initialzation of counter,
then the behavior would be undefined.
You would have no idea what the program would do.
It could even crash.
Undefined behavior, is when the behavior of the program
is not covered by the rules of C.

--
pete


这篇关于什么是差异b / w“未知”和“未定义的”行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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