fortran指针

来源:互联网 发布:编程与机械 编辑:程序博客网 时间:2024/04/29 19:32
A pointer is a
variable that has the pointer attribute.A pointer is associated with a target by allocation
or pointer assignment
具有target属性的变量,可以用指针指向该变量

program mainimplicit noneinteger,pointer ::a=>null(),b=>null()integer,target ::cinteger ::d  c=1  print*,associated(a)  a=>c  c=2  b=>c  d=a+b  print*,associated(a)  print*,a,b,c,dend



输出 2 2 2 4

The associated intrinsic returns the association status of a pointer variable
associated返回T or F,如果指针已与变量关联返回T,否则返回F


integer , pointer :: a=>null(),b=>null()
allocate(a)
a = 1
如果我们没有allocate a那么对a进行赋值是非法的

program mainimplicit noneinteger,pointer ::a=>null(),b=>null()integer,target ::cinteger ::d  allocate(a)  allocate(b)  a=100  b=200  print*,a,b  c=1  a=>c  c=2  b=>c  d=a+b  print*,a,b,c,dend


输出100 200
2 2 2 4

ALLOCATE ( allocation-list [ , STAT = stat-variable ] )

If the STAT= specifier is present, successful execution of the ALLOCATE statement causes the stat-variable to
become defined with a value of zero. If an error condition occurs during the execution of the ALLOCATE
statement, the stat-variable becomes defined with a processor-dependent positive integer value.


References
Ian Chivers / Jane Sleightholme 
Introduction to Programming with Fortran-With Coverage of Fortran 90, 95, 2003, 2008 and 77    
f90 stanard:http://www.fortran.com/f90_std.pdf
原创粉丝点击