Re: save attribute for module variables



Jugoslav Dujic wrote:
I find your reasoning logical and an "obvious thing to do", but that's not
how I parse:

"instead requiring a module variable of a user-defined type with default
initialization to be given the SAVE atribute, either directly via an explicit
initialization."

I interpret the last part of the sentence as "it is programmer's duty to attach
the SAVE attribute (one way or another)" rather than "the save-semantics is
imposed automatically by the compiler". But let's wait for James.

Your interpretation is correct: It is the programmer's duty. But you're missing the followup point, which wasn't directly stated in that quote.


If the programmer fails in this duty by omitting the SAVE, then the result becomes undefined behavior, and the compiler can do what it wants, which generally tends to be "pretend that the programmer had included the SAVE" because that's by far the easiest thing to do.

If the SAVE were not required, then the behavior with an omitted SAVE would not be undefined -- and, in particular, it would be defined as something that would be annoying to include in the compiler.

Does that clarify the interpretion any?

- Brooks


-- The "bmoses-nospam" address is valid; no unmunging needed. .



Relevant Pages

  • Re: Is this valid C statement?
    ... > Unless the type name specifies a void type, ... >any constraint), but it invokes undefined behavior, since the standard ... The ones the compiler can detect. ... They may diagnose them, but typically only if the user ...
    (comp.lang.c)
  • Re: whats wrong with atof() and casting?
    ... The return type of the function was int, ... Since atofDOES NOT return an int, this is wrong and undefined behavior. ... Note that a compiler is not required to do anything at all when you ... There is no requirement in the C standard that they do. ...
    (comp.lang.c)
  • Re: faster access private or public?
    ... > void g ... Only if the compiler can somehow prove that this code is always called ... in a context where it causes undefined behavior. ... > in this part of the code while optimizing some other piece of code? ...
    (microsoft.public.vc.language)
  • Re: [Lit.] Buffer overruns
    ... > to the C standard, ... > compiler warning there is no warning given and thus they ... suitable circumstances, trigger undefined behavior ... I have told you before how to avoid writing code ...
    (sci.crypt)
  • Re: "Mastering C Pointers"....
    ... > ANSI C" and hoping the compiler does the right thing. ... by the standard, then the amount of risk introduced becomes huge. ... and what constitutes undefined behavior. ...
    (comp.lang.c)