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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:46:47+00:00 2026-05-28T16:46:47+00:00

I wonder if volatile can be used anywhere const can, and what each case

  • 0

I wonder if volatile can be used anywhere const can, and what each case would mean.

volatile dummy_class
volatile dummy_class&
dummy_class volatile*
dummy_class *volatile
dummy_class volatile *volatile

These are all distinct cases when const is involved, do the same semantics apply for volatile?

  • 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-28T16:46:48+00:00Added an answer on May 28, 2026 at 4:46 pm

    This is section 3.9.3 CV-qualifiers from C++11 draft n3290:

    A type mentioned in 3.9.1 and 3.9.2 is a cv-unqualified type. Each type which is a cv-unqualified complete
    or incomplete object type or is void (3.9) has three corresponding cv-qualified versions of its type
    : a
    const-qualified version, a volatile-qualified version, and a const-volatile-qualified version. The term object
    type (1.8) includes the cv-qualifiers specified when the object is created. The presence of a const specifier
    in a decl-specifier-seq declares an object of const-qualified object type; such object is called a const object.
    The presence of a volatile specifier in a decl-specifier-seq declares an object of volatile-qualified object type;
    such object is called a volatile object. The presence of both cv-qualifiers in a decl-specifier-seq declares an
    object of const-volatile-qualified object type; such object is called a const volatile object. The cv-qualified or
    cv-unqualified versions of a type are distinct types; however, they shall have the same representation and
    alignment requirements (3.9).51

    So const and volatile can be used in the same spots, possibly in conjuction.

    Paragraph 3 of that section notes a slight difference in how they apply to class objects:

    Each non-static, non-mutable, non-reference data member of a const-qualified class object is const-quali-
    fied, each non-static, non-reference data member of a volatile-qualified class object is volatile-qualified and
    similarly for members of a const-volatile class. See 8.3.5 and 9.3.2 regarding function types that have
    cv-qualifiers.

    but that’s pretty logical.

    volatile-qualified objects have stricter requirements for the as-if rule, namely:

    Access to volatile objects are evaluated strictly according to the rules of the abstract machine.

    The volatility gets attached to the object in the same way const does:

    dummy_class volatile* // non-volatile pointer to volatile object
    dummy_class *volatile // volatile pointer to non-volatile object
    dummy_class volatile *volatile // volatile pointer to volatile object
    

    For non-static member functions (§9.3.1):

    A non-static member function may be declared const, volatile, or const volatile. These cv-qualifiers
    affect the type of the this pointer
    (9.3.2). They also affect the function type (8.3.5) of the member function;
    a member function declared const is a const member function, a member function declared volatile is
    a volatile member function and a member function declared const volatile is a const volatile member
    function.

    So volatility like const-ness applies to the type of this inside the function.

    Neither const nor volatile can be applied to static member functions.

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

Sidebar

Related Questions

I wonder, how can I increment a string representing a binary number, all the
Knowing that Reads and writes are atomic for all variables declared volatile Question1: Can
wonder whether someone can help me with the following one... I have a struct
I wonder about that can I write native SQL to add or delete operations
wonder if someone can help me i know what i want to achive but
I wonder if anyone can help - I want to select a table and
I wonder how it would be possible to implement a positional inverted index in
I wonder if anyone can help me understand how indices work with glDrawElements. In
Wonder if anyone can help me, the map displays fine but the marker does.
I wonder how I can best create a progress bar fragment. It must be

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.