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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:19+00:00 2026-05-23T15:20:19+00:00

My search foo seems lacking today. I would like to know if it is

  • 0

My search foo seems lacking today.

I would like to know if it is legal according to std C++ to inspect “any” memory location via an (unsigned(?)) char*. By any location I mean any valid address of an object or array (or inside an array) inside the program.

By way of example:

void passAnyObjectOrArrayOrSomethingElseValid(void* pObj) {
   unsigned char* pMemory = static_cast<unsigned char*>(pObj)
   MyTypeIdentifyier x = tryToFigureOutWhatThisIs(pMemory);
}

Disclaimer: This question is purely academical. I do not intend to put this into production code! By legal I mean if it’s really legal according to the standard, that is if it would work on 100% of all implementations. (Not just on x86 or some common hardware.)

Sub-question: Is static_cast the right tool to get from the void* address to the char* pointer?

  • 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-23T15:20:19+00:00Added an answer on May 23, 2026 at 3:20 pm

    C++ assumes strict aliasing, which means that two pointers of fundamentally different type do not alias the same value.

    However, as correctly pointed out by bdonlan, the standard makes an exception for char and unsigned char pointers.

    Thus, in general this is undefined behaviour for any pointer type to read any deliberate address (which might be any type), but for the particular case of unsigned char as in the question it is allowed (ISO 14882:2003 3.10(15)).

    static_cast does compile-time type checking, so it is unlikely to always work. In such a case, you will want reinterpret_cast.

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

Sidebar

Related Questions

I'm implementing a search in my website, and would like to support searching for
I need a some stored procedure that called like: search('foo bar') makes a search
How can I search if a file named foo.txt was ever committed to my
How do you combine two jQuery search results? eg: var $allFoos = $('.foo'), $allBars
Given: Url - http://www.contoso.com/search.php?q= {param} returns: -html- --body- {...} ---div id='foo'- ----div id='page1'/- ----div
Search Engine Optimization (SEO) seems to be a topic I'm running into more and
Search for good JAVA lib for playing with POST-GET requests - Is there any
Search for good Java lib for playing with Sockets connections - Is there any
Which search engine would you recommend for a Commerce website? We have millions of
Basically, I would like to be able to be able to pass a function_A

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.