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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:27+00:00 2026-06-08T06:04:27+00:00

I dont see what the following macro is doing? If anyone can help me

  • 0

I dont see what the following macro is doing? If anyone can help me see it it would be appreciated.

#define BASE_OFFSET(ClassName,BaseName)\
(DWORD(static_cast < BaseName* >( reinterpret_cast\
< ClassName* >(Ox10000000)))-Ox10000000)

If anyone is curious to know where it is coming from, it comes out of the 3rd chapter of Don Box Book Essential COM where he is building a QueryInterface function using interface tables and the above macro is somehow used to find the pointer to the interface vtable of the class, where class is the ClassName implementing the BaseName, although I dont know how it is doing that.

  • 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-08T06:04:28+00:00Added an answer on June 8, 2026 at 6:04 am

    It tells to the compiler: “imagine there a ClassName object at 0x10000000. Where would the BaseName data begin in that object, relative to 0x10000000″?

    Think of a memory layout of a class object with multiple bases:

    class A: B, C{};
    

    In the memory block that constitutes an A object, there’s the chunk of data that belong to B, also a chunk of data that belongs to C, and the data that are specific to A. Since the address of at least one base’s data cannot be the same as the address of the class instance as a whole, the numeric value of the this pointer that you pass to different methods needs to vary. The macro retrieves the value of the difference.

    EDIT: The pointer to the vtable is, by convention, the first data member in any class with virtual functions. So by finding the address of the base data, one finds the address of its vtable pointer.

    Now, about the type conversion. Normally, when you typecast pointers, the operation is internally trivial – the numeric value of the address does not depend on what type does it point to; the very notion of datatype only exists on the C level. There’s one important exception though – when you cast object pointers with multiple inheritance. As we’ve just discussed, the this pointer that you need to pass to a base class method might be numerically different from the one of the derived object’s.

    So the distinction between static_cast and reinterpret_cast captures this difference neatly. When you use reinterpret_cast, you’re telling the compiler: “I know better. Take this numeric value and interpret it as a pointer to what I say”. This is a deliberate subversion of the type system, dangerous, but occasionally necessary. This kind of cast is by definition trivial – cause you say so.

    By “trivial” I mean – the numeric value of the pointer does not change.

    The static_cast is a more high level construct. In this particular case, you’re casting between an object and its base. That’s a reasonable, safe cast under C++ class rules – BUT it might be numerically nontrivial. That’s why the macro uses two different typecasts. static_cast does NOT violate the type system.

    To recap:

    reinterpret_cast<ClassName* >(OxlOOOOOOO)
    

    is an unsafe operation. It returns a bogus pointer to a bogus object, but it’s OK because we never dereference it.

    static_cast<BaseName*>(...)
    

    is a safe operation (with an unsafe pointer, the irony). It’s the part where the nontrivial pointer typecast happens.

    (DWORD(...)-OxlOOOOOOO)
    

    is pure arithmetic. That’s where the unsafety doubles back on itself: rather than use the pointer as a pointer, we cast it back to an integer and forget that it ever was a pointer.

    The last stage could be equivalently rephrased as:

    ((char*)(...)-(char*)OxlOOOOOOO)
    

    if that makes more sense.

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

Sidebar

Related Questions

folks, if you dont mind please see following code : #include <glib.h> #include <gio/gio.h>
I don't necessarily see a grandiose benefit of interfaces inheriting interfaces. Consider the following
I dont see any direct mention on using multiple slugs (or any behavior for
I dont really understand whats going on and cant see the difference: I'm downloaded
Folks I am surprised to see my code working, that I dont have any
I don't see anything that I am doing wrong, but NetBeans gives me the
Please see the following statements: char a[5]=jgkl; // let's call this Statement A char
I have a application.css.scss with the following content - @import bootstrap Now I would
Please explain the following paragraph. The next question is whether we can assign a
i have a following pattern, inside the html file, that i would like to

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.