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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:29:24+00:00 2026-05-21T23:29:24+00:00

I was wondering whether the following is undefined behavior // Case 1: int *p

  • 0

I was wondering whether the following is undefined behavior

// Case 1:
int *p = 0;
int const *q = *const_cast<int const* const*>(&p);

// Case 2: (I think this is the same)
int *p = 0;
int const *const *pp = &p;
int const *q = *pp;

Is this undefined behavior by reading a int* as if it were a int const*? I think it is undefined behavior, but I previously thought that only adding const in general is safe, so I’m unsure.

  • 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-21T23:29:25+00:00Added an answer on May 21, 2026 at 11:29 pm

    Qualification-wise, it’s fine. With each expression split into a statement:

    int *p = 0; // ok
    int **addrp = &p; // ok
    int const *const *caddrq = addrp; // ok, qualification conv. according to §4.4/4
    int const *q = *caddrq; // ok
    

    Note that the rules of const_cast (§5.2.11/3) are identical to those of qualification conversion, but without the requirement of being monotonically increasing in qualification. In your case, because you’re only ever adding qualifications the const_cast is unnecessary.


    Concerning aliasing, I don’t think it’s an issue, here, or at least it’s not intended to be.

    Like you mentioned, there’s a new bullet in the C++0x list of allowed access methods (§3.10) that allows similar types (“similar” being types arising from qualification conversions). In C++03 that bullet is missing, but I suspect that the bullet about allowing more cv-qualified access was meant to cover that, but it technically isn’t so (that is, the commitee overlooked this).

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

Sidebar

Related Questions

OK I know that I may be thinking about this the wrong way but
I'm wondering what the best branching strategy is for this scenario. My company is
Just wondering about this one : Whats the difference, or is there a difference
Just wondering which Xcode syntax colouring 'theme' all you guys use, and why??
I am wondering if there is any difference in runtime between a generic container
I was wondering if there was a way to do what it says in
I'm wondering if there is clean cut functionality that returns True or False if
I'm using Goliath (which is powered by eventmachine) and the postgres gem pg ,
I'm designing a web service that clients connect to in order to retrieve some
I have a WCF service that has a complex operationcontract that has to executed

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.