我想在关联块中保留数组边界为:

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


我希望b的界限是24,但实际上它们是13。这该怎么做?提前致谢!

最佳答案

您正在与一个子数组相关联,其边界始终从1开始。

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


抱歉,您不能在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

07-24 22:13