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

Common block weirdness

WSinc
New Contributor I
953 Views
I frequently use "include" to insert a COMMON block into my code. The purpose is to make everything consistent, in case there are changes. However, I have come across something that kept me scratching my head for several days.

Subroutine sub1( argument list)
include "comn1.com"
print *,loc(array)
end subroutine !sub1

Subroutine sub2( argument list)
include "comn1.com"
print *,loc(array)
end subroutine !sub2


The array ARRAY is contained in the COMMON block COMN1. Now you would think that both PRINT statements would give the same address. I made sure that the array "array" was not duplicated in either argument list. However, upon printing out the results, the addresses were different by over a thousand bytes.

Can anyone think of a set of conditions that would cause this? One thing pertaining to this: where should the COMMON blocks be placed in the project, along with the code, in header files, or in resource files? Is it proper to give them the extension .COM or should I call them something else, i.e. .F90 or .HDR, etc? They are just treated as text files regardless, is that correct?

Perhaps going along with some standard way of doing this may make the problem go away. It appears that the linker is thoroughly confused by the way I am doing it.
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
953 Views
Different IMPLICITs in scoping units?

Is array the first element of COMN1? If not, try printing out LOCs of the previous elements and see where they start to differ.

Just a guess,
Jugoslav
0 Kudos
james1
Beginner
953 Views
Do you have a short compilable example? Are the routines in the same or separate files, how are you initializing the common, etc.

James
0 Kudos
WSinc
New Contributor I
953 Views
As far as I can tell, the difference in the LOCs is biger than the entire common block. Also all variables in the Common block are explicitly typed, and all routines have an IMPLICIT INTEGER*2(A_Z) in the header.

Unfortunately, when I try to reduce the program, the problem goes away.

Where should I put the COMMON blocks anyway? I think the linker is doing something weird to me.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
953 Views
One more stupid suggestion (but the problem is so weird that I bet that the cause is stupid): Are perhaps source files in different directories and there are two (different) copies of include file? (I remember banging my head with that one once).

Re include files: you can give them any extension you like but don't use .f90, .for or .f. CVF IDE recognizes .fd and .fi as fixed-form includes (which gives you syntax coloring) and .i90 as free-form (hmmm, does this one still work?), but that's only matter of convenience.

I think it's time to send the copy of your project to vf-support@compaq.com ... and please satisfy our curiosity as well once you find the answer.

Jugoslav
0 Kudos
Reply