On Jan 13, 2006, at 10:23 PM, Aleksandar Donev wrote:
> The NAG compiler is right, SAVE is required.
The SAVE attribute is required. However, it need not be explicit. the
variable in question is SAVEd.
> I am not quite sure where you get the idea that default
> initialization means no save.
I see how he got it, but there is confusion. The default initialization
does not itself confer the SAVE attribute in the same way as normal
(nondefault) initialization. However, the fact that something has
default initialization doesn't disable getting the SAVE attribute some
other way; it just doesn't itself give the attribute. For the case in
question, the variable has normal initialization in addition to the
default initialization. Therefore the variable does have the SAVE
attribute from the normal initialization and the NAG compiler is wrong.
As a matter of style, I personally prefer making the SAVE attribute
explicit, but that's a separate question.
Note an important distinction between default and normal
initialization. Default initialization applies to every object of a
type. Normal initialization applies to only the specified object. This
distinction has many implications, but the SAVE attribute thing is one
of them. You wouldn't really want default initialization to force every
variable of a type to be saved; there are contexts where you might want
such a variable to be nonsaved. In fact, there are plenty of contexts
where it isn't valid for a variable to be saved (such as a dummy
argument).
> In fact, in all implementations I know of it makes no actual
> difference, the module variable will be "saved" anyway.
Well, it makes no difference to how things work if they compile. But
the OP just demonstrated that it does make a difference in that some
compilers will refuse to compile code that doesn't have the SAVE
attribute. Compiling versus not compiling is a difference, though I'm
aware that isn't what you meant.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|