Before coming to the real answer, a note about terminology. In Fortran what you have here is not initialization but assignment. These are two distinct things. Yes, it's clear what is meant here but it's perhaps good to become aware of the distinction.
The lines like x=0
are intrinsic assignment statements. To the left of =
is the variable and to the right the expression. For each of these in the question there are two considerations:
- the variable and expression may differ in type or type parameter;
- the variable is an array and the expression a scalar.
As stated in a related answer, when the variable and expression differ in type or type parameter (but are type conformable as in this case) the expression is converted to the type and type parameter of the variable.
The first two assignments certainly involve type conversion: 0
is an integer and 0d0
is a (double precision) real. Although (0d0, 0d0)
is a complex - so there is no type conversion - this will be of different kind unless double precision
is the same as real(real64)
.
So, for at least the first two we have conversion like the equivalent
x = CMPLX(0, KIND=real64)
x = CMPLX(0d0, KIND=real64)
and for the third perhaps
x = CMPLX((0d0, 0d0), KIND=real64)
With
x = (0._real64, 0._real64)
we can be sure the kinds of the variable and the expression are the same.
As long as CMPLX(0, KIND=real64)
has the same value as (0._real64, 0._real64)
you can be sure that the assignment x=0
(for now, for scalar x
) has the same effect as x=(0._real64, 0._real64)
. This is mandated by the Fortran standard.
Zero is somewhat of a special case in that it appears in every model number set, but whenever a (mathematical) number is used which can be exactly represented in all three the effect will be the same. Equally,
x = 3.14_real64
and
x = (3.14_real64, 0._real64)
are equivalent.
Perhaps worth noting, though, is that some compilers with some options may offer warnings about implicit conversion. That is one difference to be observed even with the numeric values being equivalent.
Coming to the array/scalar aspect: the expression is treated as though it is an array of the same shape as the variable with every element equal to that scalar value.
To conclude: each of those three assignments has the same Fortran-effect. After the assignment x
is an array of given shape with each element having complex value (0._real64, 0._real64)
.
Now, that isn't to say that there won't be a possibility of something exciting happening at a low level, and that zero-setting may be a special case. But that's something between you and your compiler (and system).