C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extend std::type_info with more information

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 7 Apr 2024 18:59:57 +0100
On Sunday, April 7, 2024, Jens Maurer wrote:
>
>
> How would that allow to determine the type of a
> polymorphic object, where only a pointer-to-base
> might be given?



Not sure what you're asking here. Let's say we have:

  class Base { . . . };
  class Derived : public Base { . . . };

There are three possibilities here:
    (1) Neither Base nor Derived are polymorphic
    (2) Both Base and Derived are polymorphic
    (3) Only Derived is polymorphic

Specifically, which of these 3 scenarios are you asking about? Could you
give a few lines of sample code?

Oh and just as an aside . . . if you're ever doing some debugging on x86_64
Linux, and you really need to know if your 'void *p' points to a
polymorphic object, here's how to find out:

    (1) 'p' should point to a page of memory that is readable and
non-executable (i.e. pointer to an object).
    (2) The pointer located at the start of '*p' should point to a page of
memory that is read-only and not executable (i.e. pointer to a vtable).
    (3) The pointer at '**p' should point to a page of memory that is
read-only and executable (i.e. pointer to executable code).

If those 3 criteria are met, you can be confident that you're dealing with
a polymorphic object. Of course this is just for debugging /
troubleshooting though.

Received on 2024-04-07 17:59:59