forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Several Moduls

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
EKruck



Joined: 09 Jan 2010
Posts: 213
Location: Aalen, Germany

PostPosted: Fri Nov 09, 2012 8:23 am    Post subject: Using Several Moduls Reply with quote

Compared to COMMON areas MODULS have very big advantages: They can be included in DLLs and they can hold dynamic allocatable arrays.
Our new developments use only MODULS but no COMMON at all.
We have a collection of global MODULS and several local MODULS for application programs.

When e.g. a global MODUL contains a variable iPosXYZ and a local MODULE includes a variable with the same name iPosXYZ and both moduls are used inside the same function we get no warning or error message but unexpected results. This is contrary to the use of COMMON areas from INCLUDE files.

Enhancement of the compiler will be appreciated.

Erwin
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6472
Location: Salford, UK

PostPosted: Fri Nov 09, 2012 10:20 am    Post subject: Reply with quote

Thank you. I already have this as an issue to look at.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2200
Location: Sydney

PostPosted: Fri Nov 09, 2012 12:56 pm    Post subject: Reply with quote

I'm puzzled. What do you expect the compiler should do in response to having the same variable name used in 2 modules?
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 557
Location: UK

PostPosted: Sat Nov 10, 2012 10:46 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
I'm puzzled. What do you expect the compiler should do in response to having the same variable name used in 2 modules?


If the same name really does appear in two USED modules, then the code is not standard conforming and the compiler should issue an error.

But, I'm not clear what the OP means by "local module" and "global module" here. If he/she means (1) one module variable, and (2) one local variable or host associated variable of the same name, then variable (2) should take precedent over and "hide" variable (1). AFAIK this works properly in the compiler.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2200
Location: Sydney

PostPosted: Sun Nov 11, 2012 1:44 am    Post subject: Reply with quote

I have seen examples of duplicate variables, I think a variable name being both local and in a module.
I am not sure if this can be legally done, but it certainly is confusing code that I would not recommend.
My best adviced is don't do it. Fix it. There must be a way of changing the code to avoid this, even if it takes a bit of effort and checking with global editing.

John
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 557
Location: UK

PostPosted: Sun Nov 11, 2012 6:02 pm    Post subject: Reply with quote

Having a local variable with the same name as one in a USED module is OK. The local variable can be accessed and the global one can't. It isn't good practise though.

I find the best practise is to always use ONLY with USE statements:

If I want to use a local variable with the same name as one in a module, I don't include it in the ONLY list.

If I want to use a variable in a module that has the same name as one of my local variables, I usually rename one of them in the editor, or occasionally (when the module is supplied in a library and I don't have the source code), I use the rename facility with USE and prepend the module name, e.g.

Code:

SUBROUTINE AAA
    USE mymod, ONLY: mymod_var => var, a, b
    REAL :: var
   ! var and mymod_var now both accessible and easy to distinguish
END SUBROUTINE AAA


The same rules and techniques apply to subroutines and functions too.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6472
Location: Salford, UK

PostPosted: Sat Mar 16, 2013 3:40 pm    Post subject: Reply with quote

Erwin

Now I have come to look at this, I can not find a sample program to illustrate the problem.

Can you supply some sample code so that I know exactly what is happening.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2210
Location: South Pole, Antarctica

PostPosted: Sat Mar 16, 2013 10:05 pm    Post subject: Re: Using Several Moduls Reply with quote

EKruck wrote:
This is contrary to the use of COMMON areas from INCLUDE files. Erwin


Erwin,
If in local subroutine you gave the name to the variable which coincides with the same name and type variable in COMMON while is doing completely different things your are screwed. Compiler can not determine this wrong.

In MODULE case, i agree, if local and global names of variable by mistake coincide, compiler not only must issue big fat error message, it should shut down the whole computer if you keep not reacting. LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group