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

  • Home
  • SEARCH
  • 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 1017909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:46:38+00:00 2026-05-16T10:46:38+00:00

when a reinterpret_cast is applied to a class object, it returns a LONG_PTR. is

  • 0

when a reinterpret_cast is applied to a class object, it returns a LONG_PTR. is it some sort of handle to a temporary object pointer stored somewhere in memory?

  • 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-16T10:46:39+00:00Added an answer on May 16, 2026 at 10:46 am

    The question’s not so well worded. I can’t think of any manner of object for which reinterpret_cast<LONG_PTR>(object) would work, assuming LONG_PTR is some pointer type (it’s not Standard C++), and object is a class instance (the C++ Standard considers variables of built in types to be objects too – that could work).

    You may be thinking of:

    My_Class my_object;
    
    // convert an arbitrary value to a pointer
    reintrepret_cast<LONG_PTR>(1234)
    

    In this case, 1234 is never a run-time “object” – not even a temporary int in memory – it’s just a number that the compiler converts to a LONG_PTR as if you’d used static_cast<>. You can think of this as “give me a LONG_PTR with this value”.

    You could reinterpret to a reference-to-object:

    // get a LONG_PTR extracted from memory [&my_object...&my_object+1)
    reintrepret_cast<LONG_PTR&>(my_object);
    

    In this case, the pointer returned doesn’t necessarily refer to any object that your program has, or even to memory that your program can access. There is no temporary created there for your convenience (as per your question). You’re simply telling the compiler that sizeof(LONG_PTR) bytes starting at the base address of my_object ought to contain a LONG_PTR. Hopefully my_object or other code has set it somehow to point somewhere useful, or to a recognisable sentinel value like NULL. Think of this as “give me a reference to the LONG_PTR bits already stored in the front of my_object, letting me treat them as a LONG_PTR and forget all about my_object” – you’d better hope those bits/bytes are aligned in memory in a way your CPU can handle, or you could get SIGBUS or equivalent.

    You can also reinterpret a pointer-to-object to a LONG_PTR

    // get LONG_PTR that points at my_object's base address
    reintrepret_cast<LONG_PTR*>(&my_object);
    

    In this case, you know the returned value does point somewhere in your program, to valid memory, although if sizeof(LONG_PTR) is greater than sizeof(my_object), then not all the memory it addresses is within my_object: any remainder could be from another variable, the stack, or again be inaccessible. Think “give me a LONG_PTR aimed at my_object‘s memory, which should (or will if you write to it) hold the -value- that a LONG_PTR normally addresses (perhaps a “LONG”, or perhaps LONG_PTR is a generic pointer of a particular bit-size?)”.

    Note these are all very different.

    More generally, reinterpret_cast returns whatever type you pass as a template argument, which may or may not be your LONG_PTR, but there’s certainly nothing inherently in reinterpret_cast<> that relates to your LONG_PTR type.

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

Sidebar

Related Questions

My understanding is that C++ reinterpret_cast and C pointer cast is a just a
Suppose I have some pointer, which I want to reinterpret as static dimension array
i want to cast from upper class pointer to lower class i.e from the
When getting a pointer to the sip API: sip_API = reinterpret_cast<const sipAPIDef*>( PyCapsule_Import(sip._C_API, 0));
If I have this as pointer to memory as a pointer to shorts: unsigned
The reinterpret_cast as we know can cast any pointer type to any another pointer
In my application I open a handle to shared memory that I read/write to/from.
I want to reinterpret cast a function pointer into a void* variable. The type
What is the C equivalent for the reinterpret_cast from C++?
What is the PyOpenGL equivalent of #define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i)) glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_SHORT, BUFFER_OFFSET(offset)) If

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.