I would like to get clarifications about the declaration in Fortran90 or gfortran.
Firstly, for declaring integer and double, it seems that convention is:
! i is an integer
integer::i
whereas I have also seen a simple declaration like (in my code, I use this one):
! i is an integer
integer i
i.e, without the '::
' symbol.
What is the norm about this declaration (for integer, real, double
)?
Is it the same for declaring arrays ? i.e, is symbol '::
' necessary like in this following declaration:
! declaration of array "list" with 10 elements
double precision,dimension(10)::list
I looked for a simpler declaration for array, without success.
Finally, I also use the following syntax for allocatable arrays:
! Arrays
double precision, allocatable :: x(:,:)
! Allocation of 2D Array
allocate(x(1:size_x,1:size_y))
Is it a recent way (I mean a recent convention or norm in Fortran) to declare allocatable array?
PS: I don't know very well the evolution of different versions for Fortran (for example the differences between fortran90
and gfortran
.
In a variable declaration, ::
is required for one of two reasons:
For the first we see such as
integer, dimension(5) :: i
integer, target :: j
For the second
integer :: k=1
It isn't harmful to use ::
when optional/not required. Although the token isn't valid in Fortran standards before F90.
Finally, note that integer i(5)
doesn't require the ::
. I've seen advice given to use ::
always for consistency and saving effort learning/applying the rules.