What does "behave in exactly the same way" mean when no output is produced?
Any program that doesn't change anything will behave in exactly the same
way..
In the first case, a, b and c are local to each of the to subroutines. That
they have he same name in do_something and do_something_else is irrelevant.
They may be created on the stack when the routine is called and destroyed
upon exit, or (if static storage is chosen) occupy six different memory
locations.
In the second case, you have three module variables. They are guaranteed to
exist as long as the module is in use (and are likely to be static, but
don't have to be). You can put a 'print*,c' before the end of the program,
which wouldn't work in the first case.
Just received Aleksander's reply. I disagree with the PARAMETERs necessarily
being macros, although the compiler may choose to implement them like that.
HTH,
Herbert
-----Original Message-----
From: P Suckling [mailto:[log in to unmask]]
Sent: Tuesday, October 01, 2002 3:24 PM
To: [log in to unmask]
Subject: Modules, procedures, and stack storage space.
The following two modules a) and b)...
a)
MODULE a_module
CONTAINS
SUBROUTINE do_something
IMPLICIT NONE
REAL, PARAMETER :: a=1.,b=1.
REAL :: c
c=a+b
END SUBROUTINE do_something
SUBROUTINE do_something_else
IMPLICIT NONE
REAL, PARAMETER :: a=1.,b=1.
REAL :: c
c=a+b
END SUBROUTINE do_something_else
END MODULE a_module
b)
MODULE a_module
IMPLICIT NONE
REAL, PARAMETER :: a=1.,b=1.
REAL :: c
CONTAINS
SUBROUTINE do_something
IMPLICIT NONE
c=a+b
END SUBROUTINE do_something
SUBROUTINE do_something_else
IMPLICIT NONE
c=a+b
END SUBROUTINE do_something_else
END MODULE a_module
... would behave in exactly the same way when used in the following
(pointless)
program:
PROGRAM a_program
USE a_module
IMPLICIT NONE
CALL do_something
CALL do_something_else
END PROGRAM a_program
However, would use of one of either a) or b) actually require less stack
space
and therefore be more memory efficient? Does a) require two separate copies
of
the variables a and b in memory; one for each procedure do_something and
do_something else, whereas b) only needs one copy for the whole module?
Also, as
for variable c, is it the case that: For a) it is added to the stack as
procedures do_something and do_something else are called, and removed when
the
procedures return, whereas in b) its memory is always reserved on the stack?
I realise this might be a compiler dependent question, but it would be handy
if
someone could give me a feeling for how allocation of stack space works with
modules and procedures general.
Cheers, Paul.
This e-mail has been scanned by Trend InterScan Software.
This e-mail (and its attachment(s) if any) is intended for the named
addressee(s) only. It may
contain information which is privileged and confidential within the
meaning of the applicable law.
Unauthorised use, copying or disclosure is strictly prohibited and may
be unlawful.
If you are not the intended recipient please delete this email and
contact the sender via email return.
Fujitsu Laboratories of Europe Ltd (FLE) does not accept responsibility
for changes made to this email after
it was sent. The views expressed in this email may not necessarily be
the views held by FLE.
Unless expressly stated otherwise, this email does not form part of a
legally binding contract
or agreement between the recipient and FLE.
|