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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:01:54+00:00 2026-05-22T03:01:54+00:00

Given that A* pA; and B* pB; , is there ANY difference between below

  • 0

Given that A* pA; and B* pB;, is there ANY difference between below type castings (query for all C++ style casts):

pB = reinterpret_cast<B*>(pA);      // pointer
pB = reinterpret_cast<B*&>(pA);     // pointer-reference
  • 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-22T03:01:54+00:00Added an answer on May 22, 2026 at 3:01 am

    The two are radically different, at least in theory (and possibly on
    a few rare machines, in practice). The first takes a pointer to A, and
    converts it to a pointer to B; in theory, at least, this may involve
    changes in size and representation. (I’ve actually worked on machines
    where char* was larger than int*. I rather doubt that any such
    machines still exist, although perhaps in the embedded world…) The
    second is really the equivalent of *reinterpret_cast<B**>(&pA); it
    takes the bits in pA, and tells the compiler to interpret them as
    a B*. If the format is different, tough luck, and if the size is
    different, you’re likely to only access part of pA or to access memory
    which isn’t part of pA.

    Also, the first is an rvalue, the second an lvalue. Thus, something
    like:

    ++ reinterpret_cast<B*>( pA );
    

    is illegal, but:

    ++ reinterpret_cast<B*&>( pA );
    

    isn’t. This is a useful technique for obfuscating code, and getting
    unaligned pointers, pointers into the middle of objects, or other
    pointers you don’t dare dereference.

    In general, the second form should be avoided, but there are rare
    exceptions. Posix guarantees that all pointers, including pointers to
    functions (but not pointers to members—Posix specifies a C ABI,
    which doesn’t have pointers to members), have the same size and format,
    so the second form is guaranteed to work. And it is the only way you
    can legally convert the void* returned by dlsym into a pointer to
    a function:

    int (*pf)( int );
    reinterpret_cast<void*&>( pf ) = dlsym( handle, "functionName" );
    

    (In C, you’d write:

    int (*pf)( int );
    *(void**)( &pf ) = dlsym( handle, "functionName" );
    

    , see the
    official
    specification
    .) Such tricks allow conversions between pointer types
    which aren’t otherwise allowed, but depends on additional guarantees not
    in the standard.

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

Sidebar

Related Questions

Given a Task t , is there any semantic difference between t.ContinueWith(ante => DoSomethingWith(ante));
Is there any Java lib that allows me to download web pages recursively given
Is there any algorithm that gives the compass direction of a shadow given latitude,
Given an object, is there any way to get notified of when that object
Is there any difference between var obj1 = new Constructor; and var obj2 =
Is there any performance difference (in C++) between the two styles of writing if-else,
Is there any scalable Win32 API (like IOCP not like select) that gives you
Is there any straight forward way to do that? I want to give an
Given that: There seems to be no easy way to get a list of
Original Problem: I have 3 boxes each containing 200 coins, given that there is

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.