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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:39:03+00:00 2026-06-02T02:39:03+00:00

I have a function and call it: Class1& Class2::get() { return *m_ptr; } Class1&

  • 0

I have a function and call it:

Class1& Class2::get()
{
   return *m_ptr;
}

Class1& c = m_class2->get();

m_ptr is a custom smart pointer and I can see in debugger that m_ptr.m_p is 0, also I can see inside its operator T* that it really returns 0. However address of c (&c) is not NULL, it is 0x30! What I see in disassembly:

13059       return *m_ptr;
eaabbc7e:   mov 0x8(%ebp),%eax
eaabbc81:   add $0xb4,%eax
eaabbc86:   mov %eax,(%esp)
eaabbc89:   call 0xea9ce4c0  <operator T*>
eaabbc8e:   add $0x30,%eax
13060     }

Just before line add $0x30,%eax I can see that %eax is 0, that is operator correctly returned NULL.

Why the line to add 0x30 is here???

  • 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-06-02T02:39:05+00:00Added an answer on June 2, 2026 at 2:39 am

    Although there’s not enough information to answer, your comments hint that Class2 involves multiple inheritance, and I will hazard a guess that the template parameter T a derived class, not Class2 itself.

    So operator T* returns a pointer to this derived class. In order to dereference it to give Class2&, it must be converted to Class2*, which may involve adding an offset to the pointer, depending on how the compiler lays out the base class sub-objects within the object.

    Obviously this is only valid if the pointer is not null; that’s one reason why you must never dereference a null pointer even if you’re only using the result to initialise a reference.

    If the function returned Class2*, then you would get a null pointer as expected; that conversion is required to convert null to null. In your case, since you’re invoking undefined behaviour in that case by dereferencing the pointer, there’s no need for the compiler to check for null before performing the conversion.

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

Sidebar

Related Questions

I would like to have a function that can wrap any other function call.
I have a problem with the function call: [self dismissModalViewControllerAnimated:YES]; In MainViewController, I can
I have the following code in html, I cannot get the Function call back
I have the following function call from a thread: Thread Move = new Thread(){
I have function getCartItems in cart.js and I want to call that function in
I have a C program which has a function call that is defined in
I have a function void foo() and inside foo I call the function void
I have a variable that I'm using to build a JavaScript function call, and
I have a function in R that I call multiple times. I want to
I have a function that i need to call on iframe mousemove(). But i

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.