Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:02:45+00:00 2026-05-25T20:02:45+00:00

In C++03 Standard observable behavior (1.9/6) includes reading and writing volatile data. Now I

  • 0

In C++03 Standard observable behavior (1.9/6) includes reading and writing volatile data. Now I have this code:

int main()
{
    const volatile int value = 0;
    if( value ) {
    }
    return 0;
}

which formally initializes a volatile variable and then reads it. Visual C++ 10 emits machine code that makes room on the stack by pushing a dword there, then writes zero into that stack location, then reads that location.

To me it makes no sense – no other code or hardware could possibly know where the local variable is located (since it’s in automatic storage) and so it’s unreasonable to expect that the variable could have been read/written by any other party and so it can be eliminated in this case.

Is eliminating this variable access allowed? Is accessing a volatile local which address is not known to any other party observable behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:02:46+00:00Added an answer on May 25, 2026 at 8:02 pm

    The thread’s entire stack might be located on a protected memory page, with a handler that logs all reads and writes (and allows them to complete, of course).

    However, I don’t think MSVC really cares whether or how the memory access might be detected. It understands volatile to mean, among other things, “do not bother applying optimizations to this object”. So it doesn’t. It doesn’t have to make sense, because MSVC is not interested in speeding up this kind of use of volatile.

    Since it’s implementation-dependent whether and how observable behavior can actually be observed, I think you’re right that an implementation can “cheat” if it knows, because of details of the hardware, that the access cannot possibly be detected. Observable behavior that has no physically-detectable effect can be skipped: no matter what the standard says, the means to detect non-conforming behavior are limited to what’s physically possible.

    If an implementation fails to conform to the standard in a forest, and nobody notices, does it make a sound? Kind of thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could have also phrased this as What constitutes observable behavior? The C++ Standard
In C++03 Standard observable behavior (1.9/6) includes calls to library I/O functions . Now
Can standard pointers in .Net do this? Or does one need to resort to
In standard php or source code based projects we easily keep all of the
The standard data source configuration in JBoss requires the username and password of the
standard C lib: int fputc(int c , FILE *stream); And such behaviors occured many
Refactoring standard onClick within html tag to listeners ,faced problem with my code: var
The standard includes macros line _____LINE_____ & _____FILE_____, and C99 adds _____FUNCTION_____ which is
I have problem, my Knockout ViewModel is NO function and this IS NEEDED: vmNeu
The standard output of @Html.HiddenFor(model => model.Id) is <input data-val=true data-val-number=The field Id must

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.