Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > UB query

Reply
Thread Tools

UB query

 
 
Simon P Simonson
Guest
Posts: n/a
 
      12-31-2009
On Dec 30, 8:07 pm, Keith Thompson <ks...@mib.org> 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...
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-31-2009
Simon P Simonson <> writes:
> On Dec 30, 8:07 pm, Keith Thompson <ks...@mib.org> 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) kst- <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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET won't retrieve query results that depend on union query Eric Nelson ASP .Net 5 02-04-2009 10:51 PM
Trying to query the Address table data of AdventureWorks database from Query Analyzer - need help! Learner ASP .Net 1 01-30-2006 08:58 PM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
CAML Query: Multiple Query Fields Issue Jon F. ASP .Net Web Services 0 05-12-2004 08:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57