Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Initialization twice?

adaptiverotor
Beginner
745 Views
hi:
I tried to initialize a variable in block data, twice, like:
block data
common /test/ x
data x/0.5/
data x/0.6/
end

the result is x=0.5.
can I change some settings to let it initialize more than twice?
Thank you
0 Kudos
4 Replies
Steven_L_Intel1
Employee
745 Views
More than twice? It's invalid Fortran to do it more than once. The compiler will complain if you turn on standards checking. If you do this, you get the first value and the second is ignored. You can try a third and the same thing will happen.

I very strongly recommend against your depending on this behavior. It's going to bite you later.
0 Kudos
adaptiverotor
Beginner
745 Views
this happened when I use intel compiler to compile an old code which is developed in 1980's. in the code, an array is initialized in block data, and some variables are set to be EQUIVALENCE with the elements of the array. then the variables are initialized again. like:
COMMON/XFLOAT/A(500)
DATA A/500*55555.0/
EQUIVALENCE (A( 1), PHI )
EQUIVALENCE (A( 2), THET )
EQUIVALENCE (A( 3), PSI ) ......

DATA PHI/0.0/, THET/0.0/, PSI/0.0/
.....
the original code is huge. under CVF, the A(1),A(2),A(3) are initialized with 0 but IVF initialize them as 55555.0.
I can delete DATA A/500*55555.0/ to achieve the same results as CVF, but there might be some other thing different cause not all the elements of A are initialized as zero.
0 Kudos
DavidWhite
Valued Contributor II
745 Views

According to your code all the elements of A should be 55555.0. My reading of this is that CVF is in error, not IVF.

0 Kudos
Steven_L_Intel1
Employee
745 Views
The code is not legal Fortran and the results are unpredictable. I suggest compiling with standards checking on to see where the compiler complains about multiple definition and then do whatever is needed to correct the code.
0 Kudos
Reply