This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Determination of argument passed to operator new
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Nikolaus Dunn <nikdunn1979 at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 14 Oct 2016 18:29:44 +0100
- Subject: Re: Determination of argument passed to operator new
- Authentication-results: sourceware.org; auth=none
- References: <d42b085f-f1b6-fb96-4caa-bb51971d6ac7@gmail.com>
On 14 October 2016 at 18:26, Nikolaus Dunn wrote:
> Hi all,
>
> According to what I've read, the "new" and "new []" expressions are
> implemented by the compiler to compute the size of the storage required by
> the type and then make a call to one of the "new" operators to allocate
> memory and handle construction. I've found the code for the "new" operators
> in gcc, but I can't find where in the gcc code the compiler determines the
> value to be passed to the new operator and then sets up the actual call.
Look for build_new() in gcc/cp/init.c
> The reason I'm asking is I am interested in how the compiler implements the
> "new []" expression. In particular, how it is storing the array size and is
> there any extra overhead being stored and what it is, if any.
That is specified by the ABI, see
https://mentorembedded.github.io/cxx-abi/abi.html#array-cookies
> I'm assuming it is the actual parser/code generator that is doing this since
> they are unique expressions and not simply function calls. Can someone point
> me to where this code is being generated or correct my ignorance if I am way
> off base?