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 8992745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:01:46+00:00 2026-06-15T23:01:46+00:00

This is basically a continuation of this question . So far it looks like

  • 0

This is basically a continuation of this question. So far it looks like that if I have a function like this:

void SecureZeroMemory( void* ptr, size_t cnt )
{
   volatile char *vptr = (volatile char *)ptr;
   while (cnt) {
       *vptr = 0;
       vptr++;
       cnt--;
   }
}

and call it like this:

{
    char buffer[size];
    SecureZeroMemory( buffer, size );
}

then since buffer is not declared volatile it doesn’t matter that a pointer to volatile is used – the data itself is not volatile, so write to the variable do not constitute observable behavior (1.9/6) and the compiler is allowed to optimize them away.

However recently I’ve come across a statement that it’s only the pointer declaration that matters. Specifically C++03 5.3.1/1 describes indirection (*) like this:

The unary * operator performs indirection […] If the type of the expression is “pointer to T,” the type of the result is “T.”

So the claim is that because of using indirection on a volatile char* we get volatile char and writes to those do constitute observable behavior and it no longer matters how the actual data is declared.

Does the C++03 5.3.1/1 description of indirection really guarantee that overwriting memory using a volatile T* pointer as in the sample above constitute observable behavior and is disallowed to be optimized away?

  • 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-06-15T23:01:48+00:00Added an answer on June 15, 2026 at 11:01 pm

    I’m pretty sure all that “new” quote adds is that *vptr is an lvalue expression with type volatile char.

    The type of the lvalue doesn’t affect the type of the object to which that lvalue expression refers, for the same reason that a pointer-to-const that points at a non-const object doesn’t somehow make the object const. So the original analysis isn’t affected this quote — the object still doesn’t have volatile-qualified type.

    In normal parlance we’d say that the type of *vptr is volatile char &, but 5/5 says, “If an expression initially has the type “reference to T” the type is adjusted to T prior to any further analysis”. That’s the reason why *vptr is said to have type volatile char, not volatile char & — before analysing any expression you remove the reference from the type, even if it’s an lvalue.

    [Edit: my answer used to have some text about cv-qualifications being insignificant for non-object values of integer type. It was true (lvalue-to-rvalue conversions of non-class types discard cv-qualifiers, 4.1/1) but irrelevant (I mistakenly thought that because the text you quoted mentioned a non-reference type it was talking about the type after this conversion)]

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

Sidebar

Related Questions

I have an ajax function which looks like this (basically, it's simplified): function getPage(targetURL,
Basically I have run-time loaded class that looks like this: [Plugin(Plugin name)] class PluginActions
i have one dictionary that has entries that looks like this: dictionary[ABC.123] = Test
This is basically a continuation from my previous question . Seeing that my fixed
This is basically a 'best practices' question. Struts 1 forms have getters and setters
The layout looks like this: Basically all I want is to find out if
My document looks like this: Basically the background is one full-screen, transparent div. There
This is a continuation of the question excel different SUM.IF array function , But
This is basically a math problem, but very programing related: if I have 1
This is basically a duplicate of this question , but the accepted answer was

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.