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

I've managed to boil this down to the following test case but I'm wondering
I was wondering whether you think the following code usually indicates a bad design
I have the following code but it seems to not connect, just wondering whether
I am wondering whether I can use the this keyword inside a C# lambda,
I'm looking to do something like the following in Java and was wondering whether
Consider the following Scala case class: case class WideLoad(a: String, b: Int, c: Float,
I am using annoted Hibernate, and I'm wondering whether the following is possible. I
I am wondering whether I can do the following efficiently in Matlab. Writing a
I was wondering whether the following command (from a .bat script): (1) connects to
I was wondering whether the following can be easily implemented in OpenGL: divide window

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.