2012-11-27 60 views

回答

4

您關聯到一個子陣,它的邊界始終從1開始嘗試

print *, lbound(a(:,1),1) 

AFAIK你不能在associate結構使用指針重映射伎倆。具體做法是:「If the selector is an array, the associating entity is an array with a lower bound for each dimension equal to the value of the intrinsic LBOUND(selector).

但是,你當然可以用指針

integer,target :: a(2:4,2) 

integer,pointer :: c(:) 


associate (b => a(:,1)) 
    print *, lbound(b), ubound(b) 
end associate 

c(2:4) => a(:,1) 
print *, lbound(c), ubound(c) 

end 
+0

感謝弗拉基米爾!我使用ASSOCIATE塊的原因是爲了避免額外的聲明(例如指針)。希望將來能夠支持這一點。 –

0

我認爲要保持數組邊界更優雅的方式將做到以下幾點:

integer,target :: a(2:4,2) 
integer,pointer :: b(:) 

b(lbound(a,1):) => a(:,1)