Re: Component Initialization of Module Variables
- From: mecej4 <mecej4@xxxxxxxxxxxxxxxxx>
- Date: Wed, 04 Mar 2009 12:25:03 -0600
Richard Maine wrote:
<michaelmetcalf@xxxxxxxxxxxxxx> wrote:<<<--- CUT --->>>
On Mar 4, 3:50 pm, Janus Weil <jaydu...@xxxxxxxxxxxxxx> wrote:[code elided]
This is rejected by g95 with
Error: Module variable 'tve' at (1) with a component
initialization must have the SAVE attribute
while it is accepted by the other compilers I tried (gfortran
& ifort). Now my question: Is g95 right to reject this, or is
it a bug? My guess is that since VE_real is ALLOCATABLE,
there should be no default initialization, and the error
message is bogus. Right?
You say you tested this with ifort, but my version also,
correctly, gives a warning message. Objects like these, when
declared in a module, are required to have the save attribute
("Fortran 95/2003 Explained", Section 7.5.4).
I didn't go back and check the standard to make sure all was
correct, but probably so. It sounds familiar and I'll assume
Michael has it right.
I'm just posting to ask why the OP would think that default
initialization would not apply to allocatables in any case. That
would be an oddity in the standard. While it does have several
oddities, I don't know of that one.
From section 7.5.4 of MR&C: "...default initialization does notimply that the objects have the 'save' attribute. However, an
object of such a type that is declared in a module is required to
have the 'save' attribute unless it is a pointer or an
allocatable array. This is because of the difficulty that some
implementations would have with determining when a non-saved
object would need to be re-initialized."
The OP may have read this excerpt before posting. To a normal user
who does not worry about how the compiler would go about
implementing the attributes, the error message would appear to be
a compiler bug. And, the fact that one compiler signals 'error'
and another 'warning' suggests that it may be not an easy feat to
extract the rules from a standards documents, which itself is not
available at reasonable cost.
-- mecej4
.
- Follow-Ups:
- Re: Component Initialization of Module Variables
- From: Craig Powers
- Re: Component Initialization of Module Variables
- From: Richard Maine
- Re: Component Initialization of Module Variables
- References:
- Component Initialization of Module Variables
- From: Janus Weil
- Re: Component Initialization of Module Variables
- From: michaelmetcalf
- Re: Component Initialization of Module Variables
- From: Richard Maine
- Component Initialization of Module Variables
- Prev by Date: Re: Component Initialization of Module Variables
- Next by Date: Re: Monte Carlo computation of PI with license numbers
- Previous by thread: Re: Component Initialization of Module Variables
- Next by thread: Re: Component Initialization of Module Variables
- Index(es):
Relevant Pages
|