Fortran是否具有未定义的行为? [英] Does Fortran have undefined behavior?

查看:107
本文介绍了Fortran是否具有未定义的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C和C ++中,有许多操作会导致未定义的行为,即允许编译器执行所需操作的情况. 示例包括在取消分配变量后使用变量,两次取消分配变量并取消引用空指针.

In C and C++, there many operations that cause undefined behavior, i.e. situations that allow the compiler to do anything it wants. Examples include using a variable after deallocating it, deallocating a variable twice and dereferencing null pointers.

Fortran是否也具有未定义的行为?我看了一份规范草案,但未能在其中找到任何东西.例如,在释放变量之后使用变量肯定会导致程序崩溃,还是它会默默地做错事?

Does Fortran also have undefined behavior? I had a look at a specification draft, but failed to find anything in there. For instance, is using a variable after its deallocation guaranteed to crash the program, or may it silently do the wrong thing?

推荐答案

是的.只是被称为不同.您可以做很多事情,并使您的代码不符合标准的要求,因此不需要处理器(编译器)诊断此类不符合项(当然,必须进行许多偏离)被诊断).通常情况将类似于C的未定义行为(例如访问数组越界,有符号整数溢出等).我们只是说该代码不符合标准,这意味着该标准并未规定此类代码的结果.此类代码未涵盖在标准中,因此,如果某些编译器(处理器)对它进行编译并且您运行了它,则任何事情都可能会导致.

Yes, it has. It is just called differently. There are many things that you could do and will make your code not standard conforming, for which there is no requirement to for the processor (compiler) to diagnose such non-conformance (of course, many deviations must be diagnosed). Often the situations will be similar to C undefined-behaviour one (like accesing an array out-of-bounds, signed integer overflow,...). We just say that the code is not standard conforming, that means the standard does not prescribe the outcome of such a code. Such code is not covered but the standard and so anything can result if some compiler (processor) does compile it and you do run it.

依赖处理器的行为不同,它是标准的,仅依赖于实现.

That is different from processor dependent behaviour, that one is standard and just implementation dependent.

只需在StackOverflow上进行搜索即可为您提供大量示例.就像是否将同一实体传递给具有不同意图未定义行为的参数?

Just searching here at StackOverflow should give you plenty of examples. Like Is passing the same entity to arguments with different intent undefined behavior? How do Fortran and MPI_Reduce deal with integer overflow?

这篇关于Fortran是否具有未定义的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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