为什么Fortran POINTER需要一个TARGET? [英] Why does a Fortran POINTER require a TARGET?

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

问题描述

为什么 Fortran 90规范指定(5.2。 8)必须使用TARGET关键字来将POINTER关联到它?为什么不是每个类型都是有效的TARGET?



例如,

 
INTEGER, POINTER :: px
INTEGER,TARGET :: x
x = 5
px => x


有效的语法,但是

 
INTEGER,POINTER :: px
INTEGER :: x
x = 5
px => x


无效



为什么必须这样?

解决方案

指向可能被别名为别的项目,编译器必须允许这样做。没有目标属性的项目不应该被别名,编译器可以根据这个假设做出假设,从而生成更高效的代码。


Why does the Fortran 90 Specification specify (5.2.8) that the TARGET keyword must be used to associate a POINTER to it? Why isn't every type a valid TARGET?

For example,

INTEGER, POINTER :: px
INTEGER, TARGET :: x
x = 5
px => x

is valid syntax but

INTEGER, POINTER :: px
INTEGER :: x
x = 5
px => x

is not valid.

Why must this be?

解决方案

An item that might be pointed to could be aliased to another item, and the compiler must allow for this. Items without the target attribute should not be aliased and the compiler can make assumptions based on this and therefore produce more efficient code.

这篇关于为什么Fortran POINTER需要一个TARGET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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