UB query

Discussion in 'C Programming' started by Simon P Simonson, Dec 31, 2009.

  1. On Dec 30, 8:07 pm, Keith Thompson <> wrote:
    > Here's what the standard says (C99 6.7.3p6):
    >
    > An object that has volatile-qualified type may be modified
    > in ways unknown to the implementation or have other unknown
    > side effects. Therefore any expression referring to such an
    > object shall be evaluated strictly according to the rules of
    > the abstract machine, as described in 5.1.2.3. Furthermore,
    > at every sequence point the value last stored in the object
    > shall agree with that prescribed by the abstract machine, except
    > as modified by the unknown factors mentioned previously. What
    > constitutes an access to an object that has volatile-qualified
    > type is implementation-defined.
    >
    > with a footnote:
    >
    > A volatile declaration may be used to describe an object
    > corresponding to a memory-mapped input/output port or an object
    > accessed by an asynchronously interrupting function. Actions
    > on objects so declared shall not be ‘‘optimized out’’
    > by an implementation or reordered except as permitted by the
    > rules for evaluating expressions.
    >
    > On the other hand, if you just apply "volatile" to a local variable,
    > the compiler can reasonably know that there's no magic going on behind
    > the scenes. It's not clear whether the compiler is permitted to take
    > advantage of this knowledge; I'd say it probably isn't.


    OK but is that footnote normative? I would be surprised if so.

    It does appear that this is a gray area in the standard that needs
    clarifying.

    My suggestion would be to change the semantics of volatile for a local
    (automatic) variable, to mean that accesses to the variable would be
    guaranteed atomic (so the compiler would automatically insert a mutex to
    protect accesses, if the variable's type cannot be accessed atomically on
    the host architecture). Assuming that the C standard follows the next C++
    standard in including multithreading support, this issue will have to be
    addressed anyway, and using the already existing volatile keyword seems
    to take care of this very neatly.

    My $0.02...
     
    Simon P Simonson, Dec 31, 2009
    #1
    1. Advertising

  2. Simon P Simonson <> writes:
    > On Dec 30, 8:07 pm, Keith Thompson <> wrote:
    >> Here's what the standard says (C99 6.7.3p6):
    >>
    >> An object that has volatile-qualified type may be modified
    >> in ways unknown to the implementation or have other unknown
    >> side effects. Therefore any expression referring to such an
    >> object shall be evaluated strictly according to the rules of
    >> the abstract machine, as described in 5.1.2.3. Furthermore,
    >> at every sequence point the value last stored in the object
    >> shall agree with that prescribed by the abstract machine, except
    >> as modified by the unknown factors mentioned previously. What
    >> constitutes an access to an object that has volatile-qualified
    >> type is implementation-defined.
    >>
    >> with a footnote:
    >>
    >> A volatile declaration may be used to describe an object
    >> corresponding to a memory-mapped input/output port or an object
    >> accessed by an asynchronously interrupting function. Actions
    >> on objects so declared shall not be ‘‘optimized out’’
    >> by an implementation or reordered except as permitted by the
    >> rules for evaluating expressions.
    >>
    >> On the other hand, if you just apply "volatile" to a local variable,
    >> the compiler can reasonably know that there's no magic going on behind
    >> the scenes. It's not clear whether the compiler is permitted to take
    >> advantage of this knowledge; I'd say it probably isn't.

    >
    > OK but is that footnote normative? I would be surprised if so.

    [snip]

    Footnotes are never normative. In theory, they just provide
    clarification of information that's already stated in the normative
    text. In practice, the standard is an imperfect document written by
    imperfect humans, and things don't always work out correctly. I'm
    particularly disturbed by the use of "shall" in this footnote.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 31, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    1
    Views:
    990
    Marina Levit [MVP]
    Jan 30, 2006
  2. Anonymous
    Replies:
    0
    Views:
    1,479
    Anonymous
    Oct 13, 2005
  3. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    796
    David Gordon
    May 18, 2005
  4. Eric Nelson
    Replies:
    5
    Views:
    1,533
    Alexey Smirnov
    Feb 4, 2009
  5. Jon F.

    CAML Query: Multiple Query Fields Issue

    Jon F., May 12, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    758
    Jon F.
    May 12, 2004
Loading...

Share This Page