Clicky

Fortran Wiki
c_sizeof

Description

c_sizeof(x) calculates the number of bytes of storage the expression x occupies.

Standard

Fortran 2008

Class

Intrinsic function

Syntax

n = c_sizeof(x)

Arguments

  • x - The argument shall be an interoperable data entity.

Return value

The return value is of type integer and of the system-dependent kind c_size_t (from the iso_c_binding module). Its value is the number of bytes occupied by the argument. If the argument has the pointer attribute, the number of bytes of the storage area pointed to is returned. If the argument is of a derived type with pointer or allocatable components, the return value does not account for the sizes of the data pointed to by these components.

Example

use iso_c_binding
integer(c_int) :: i
real(c_float) :: r, s(5)
print *, (c_sizeof(s)/c_sizeof(r) == 5)
end

The example will print .true. unless you are using a platform where default real variables are unusually padded.

See also

storage_size

category: intrinsics