You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含可分配数组的Fortran派生类型sizeof计算疑问咨询

含可分配数组的Fortran派生类型sizeof计算疑问咨询

嗨,我最近在研究Fortran派生类型的sizeof计算时,碰到了一个让我困惑的问题,想请教下各位大佬:

首先看这个简单的派生类型:

type structInt
    integer :: n
    double precision :: f
end type structInt

type(structInt) :: a

我在自己的系统上调用sizeof(a)得到的结果是16字节,考虑到内存对齐会自动填充字节,这个结果是完全合理的,我能理解。

但当派生类型里包含可分配数组时,情况就超出我的预期了:

type structArray
    integer, dimension(:), allocatable :: arr
end type structArray

type(structArray) :: b

这时候sizeof(b)的结果直接跳到了64字节!我翻遍了Fortran标准,也没找到明确说明这种行为的条款,我本来以为这个派生类型的大小应该和单独的arr参数的大小一致才对,有没有人能帮我解释下为什么会这样呀?

备注:内容来源于stack exchange,提问作者Squirrel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 12:09:08