This is the mail archive of the
mailing list for the GCC project.
Re: How to identify the type of the object being created using the new operator?
- From: Swati Rathi <swatirathi at cse dot iitb dot ac dot in>
- To: GCC Development <gcc at gcc dot gnu dot org>
- Cc: Marc Glisse <marc dot glisse at inria dot fr>
- Date: Mon, 06 Oct 2014 14:59:23 +0530
- Subject: Re: How to identify the type of the object being created using the new operator?
- Authentication-results: sourceware.org; auth=none
- References: <543256B6 dot 10807 at cse dot iitb dot ac dot in> <alpine dot DEB dot 2 dot 11 dot 1410061056150 dot 1621 at laptop-mg dot saclay dot inria dot fr>
On Monday 06 October 2014 02:28 PM, Marc Glisse wrote:
On Mon, 6 Oct 2014, Swati Rathi wrote:
Statement : A *a = new B;
gets translated in GIMPLE as
1. void * D.2805;
2. struct A * a;
3. D.2805 = operator new (20);
4. a = D.2805;
A is the base class and B is the derived class.
In statement 3, new operator is creating an object of derived class B.
By analyzing the RHS of the assignment statement 3, how can we
identify the type (in this case B) of the object being created?
I strongly doubt you can. It is calling B's constructor that will turn
this memory region into a B, operator new is the same as malloc, it
only returns raw memory.
(If A and B don't have the same size, the argument 20 can be a hint)
Argument 20 is the size of class B.
This was obtained only if we knew that object B is created here.
Is this information not stored anywhere else?