042. Zero-size array constructor#
topic: Arrays
[data_type ::]
is a zero-size array of type data_type
.
See examples below.
program zero_size
implicit none
associate ( &
r0 => [real ::], &
d0 => [real(kind(1.0d0)) ::], &
i0 => [integer ::], &
c20 => [character(len=2) ::], &
c50 => [character(len=5) ::])
print *, size(r0), kind(r0) ! 0 4
print *, size(d0), kind(d0) ! 0 8
print *, size(i0), kind(i0) ! 0 4
print *, size(c20), len(c20) ! 0 2
print *, size(c50), len(c50) ! 0 5
end associate ! Required
end program zero_size
0 4
0 8
0 4
0 2
0 5
From the Tweet comments, one potential use for this is that
“if a procedure has a required argument that is an integer array,
you can pass [integer ::]
from the caller.”
Note
The associate
construct, used here,
“yields simple abbreviations for more complex statements.
It can be an alias for expressions or variables.”2
[data_type :: ] is a zero-size array of type data_type.pic.twitter.com/XmBx5W4ZBG
— FortranTip (@fortrantip) December 23, 2021