如何在gfortran中获得sizeof double

时间:2015-08-06 13:03:08

标签: fortran gfortran

print *, sizeof(DOUBLE)

给了我4个

DOUBLE PRECISION x 
print *, sizeof(x)

给了我8(我认为是正确的)

不幸的是,这不会编译:

print *, "size of DOUBLE:",  sizeof(DOUBLE PRECISION)

有没有办法在一个sizeof()调用中实现这个目的?

1 个答案:

答案 0 :(得分:2)

sizeof is a GNU extension and, therefore, not necessarily portable.

From the documentation:

The argument shall be of any type, rank or shape.

So the following works:

program test
  print *,sizeof(1.d0)
end program

1.d0 is a double precision literal. To get the size of a single precision float, use 1.e0 or 1..