- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It tells me I have a "multiply defined symbol," but the symbol is
the name of a COMMON block.
Of course one would have the same COMMON block in different routines.
The name of the COMMON region is only used for that, nothing else.
They are all the same size and content. It appears in several routines.
What could cause that? How can I isolate tit?
Would I get that if they were diffent sizes (by accident)?
This may have to do with having record structures in the Common block,
but I am just guessing.
the name of a COMMON block.
Of course one would have the same COMMON block in different routines.
The name of the COMMON region is only used for that, nothing else.
They are all the same size and content. It appears in several routines.
What could cause that? How can I isolate tit?
Would I get that if they were diffent sizes (by accident)?
This may have to do with having record structures in the Common block,
but I am just guessing.
Link Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suggestion: COMMON is obsolete. Put the content in a module, once, and then USE the module wherever needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will try that.
But, obsolete or otherwise, why should there be a problem with this?
But, obsolete or otherwise, why should there be a problem with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ensure that only one instance of the common block has initialization(s) of its contents.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You mean like a DATA statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. Often, a BLOCK DATA subprogram was used to initialize variables that belonged to common blocks. Only one such subprogram is allowed, which helps avoid multiple initializations. If, instead, common blocks are defined in more than one place and have DATA declarations for common block variables in more than one place, linker errors arise such as those that you ran into.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem usually occurs when you have an include file that declares the COMMON and has DATA statements to initialize the COMMON. As has been said, you are allowed to initialize the common only once in a program. On some operating systems, the linker allows multiple initializations and uses a "last wins" approach. Most others, including Windows and Linux, disallow this.
The usual solution is to move the initializations to a BLOCK DATA subprogram that also includes the COMMON declarations.
The usual solution is to move the initializations to a BLOCK DATA subprogram that also includes the COMMON declarations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried replacing the COMMON blocks with modules.
But then the problem I encountered was:
I don't any longer have a way to initialize the variables to something at the
very start of execution.
For example some non-arrays need to be set =ZERO.
So, what would I use to replace the DATA statements?
It won't let me me inititalize variable that way any longer.
Can I assume that they have some initial value, or are they just random like before?
But then the problem I encountered was:
I don't any longer have a way to initialize the variables to something at the
very start of execution.
For example some non-arrays need to be set =ZERO.
So, what would I use to replace the DATA statements?
It won't let me me inititalize variable that way any longer.
Can I assume that they have some initial value, or are they just random like before?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can continue to use data statements - they just need to be in the module that declares the module variable. If you still have issues with them then elaborate.
You can also use the F90 style of initialization - where you put the initial value after a '=' in the type declaration statement for the variable. This is what I prefer.
[fortran]MODULE SomeVariables IMPLICIT NONE ! Data... REAL :: a DATA a/45.6/ ! F90 style... INTEGER :: b = 123 END MODULE SomeVariables [/fortran]
You can also use the F90 style of initialization - where you put the initial value after a '=' in the type declaration statement for the variable. This is what I prefer.
[fortran]MODULE SomeVariables IMPLICIT NONE ! Data... REAL :: a DATA a/45.6/ ! F90 style... INTEGER :: b = 123 END MODULE SomeVariables [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
According to the standard, any DATA statements used to initialize COMMON must be in a BLOCK DATA, with all DATA statements or f90 style initialization referring to a given labeled COMMON being in a single BLOCK DATA. Most compilers accept COMMON initialization other than in BLOCK DATA, but Steve explained that you must not scatter initialization of a given COMMON across more than one procedure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
we're not talking about Common blocks any more, here.
If I want to abandon Common regions, then I guess I will use Steve's suggestion about the = sign.
If I keep any Common blocks, I would just use BLOCK DATA as suggested.
If I want to abandon Common regions, then I guess I will use Steve's suggestion about the = sign.
If I keep any Common blocks, I would just use BLOCK DATA as suggested.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page