为什么 Fortran POINTER 需要 TARGET?
为什么 Fortran 90 规范 指定 (5.2.8)必须使用 TARGET 关键字将 POINTER 与其关联吗?为什么不是每种类型都是有效的目标?
例如, <代码>
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能指向的项目可以别名为另一个项目,编译器必须允许这种情况。没有目标属性的项目不应使用别名,编译器可以基于此做出假设,从而生成更有效的代码。
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 中的指针与 C 中的指针不同。在 Fortran 90 中,指针几乎没有像目标一样的限制。这样做是为了解决速度问题并保证指针使用的安全。尽管一次调用会产生不需要指定目标的可分配指针。深入挖掘,你会发现它们!
Pointers in fortran are different than pointers in c. In fortran 90 pointers were provided with few restriction like having a target. This was done to address speed issue and to keep pointer usage safe. Although one call make allocatable pointers which do not need to specify a target. Dig deeper and you will find them!!
为了更好的编译器优化。当您的代码在 1K-100K 核心上运行时,速度就很重要。
顺便说一句,TARGET 并不总是被使用。例如,在使用指针分配内存的情况下。
For better compiler optimization. When your code runs on 1K-100K cores speed does matter.
Btw TARGET is not always used. For example in situations when the pointer is being used for allocating memory.