Re: Component Initialization of Module Variables



mecej4 <mecej4@xxxxxxxxxxxxxxxxx> wrote:

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

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.

I don't see that. I have elided all the other material, including quotes
from the standard and from textbooks, leaving just the error message as
I'd expect a "normal user" to see it, not surrounded by reference
materials.

I don't see anything in it that hints at compiler bug. In fact, I'd say
that the message seemed admirably clear to me. The variable in question
has "component initialization", which isn't a term used in the standard,
but is to me an eminently more obvious term. That's the initialization
of the components, which you can see right there in the type definition.
The details of when and why the initialization applies aren't obvious,
but that's much more for the language lawyers. I would think it obvious
to even the most casual of readers that "component initialization"
probably had to do with the initialization of the components,
particularly since the type in question has such.

And the message says that the variable must have the SAVE attribute.
What about that brings compiler bug to mind?

Finding different behaviors in different compilers is something that I'd
agree can at least raise the question, but that's not a fault of the
error message.

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,

I'm going to disagree with that as well. Oh, I agree that the standards
documents can be hard to read. But I don't at all agree that having one
compiler signal an error where another signals a warning suggests that
at all. To the contrary, it suggests to me that both compiler writers
read the standard in exactly the same way. The difference I see is that
one choose to allow the practice anyway as an extension. Messages about
extensions are normally warnings unless one uses compiler switches to
deliberately change them to errors.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: Uninitialized variables
    ... > unintialized variables to zero on the old CVF forum, ... > eems reals and integers have a default initialization of the largest ... The Fortran compiler no longer "owns" the linker/OS ... all of the time and the standard doesn't ...
    (comp.lang.fortran)
  • Re: OT: Requesting C advice
    ... some behind the scenes action of the compiler. ... In fact the memory could ... Proper initialization means that floats and doubles must be initialized to 0.0 and pointers must be initialized to the null pointer value, even if those bit patterns differ from all-bits-zero. ...
    (Fedora)
  • Re: initializing static class variables
    ... >> I believe it was introduced in 2003 standard but I can't be sure since I ... >> default constructor is called. ... the definition of compiler generated default constructor. ... constructed with default initialization. ...
    (comp.lang.cpp)
  • Re: Component Initialization of Module Variables
    ... there should be no default initialization, ... I didn't go back and check the standard to make sure all was ... initialization would not apply to allocatables in any case. ... who does not worry about how the compiler would go about ...
    (comp.lang.fortran)
  • Re: I think C# is forcing us to write more (redundant) code
    ... static void F(out string s) ... >> compiler enforced). ... locals here and locals are stack allocated, ... I don't have a problem with this explicit initialization in the current ...
    (microsoft.public.dotnet.languages.csharp)