I am just porting some old code:
#define NewArrayOnHeap(TYPE, COUNT, HEAP, NEWPTR, ERROR) \
((*(NEWPTR) = new ( #TYPE "[" #COUNT "]", __alignof(TYPE), (HEAP), &hr, (ERROR)) TYPE[COUNT] ), hr)
It looks like the original was supposed to define their own magical new
operator. I am curious about this usage.
Example usage
int main()
{
void* heap = /* Don't know how to define this */
double* ptr;
HRESULT hr;
hr = NewArrayOnHeap(double, 10, heap, ptr, "Help /* Just guessing here */");
}
When I use g++ -E
to get the preprocessor output, it's:
int main()
{
double* ptr;
HRESULT hr;
hr = ((*(ptr) = new ( "double[ 10 ]", __alignof(double), (NULL), &hr, ("Help")) double[10] ), hr);
}
This looks slightly more like a placement new
.
But is this now an overloaded new call (with some funky parameters, a five parameter new
call), or are the commas here the comma operator and thus it gets reduced to ("Help")
(which wouldn't make sense).
Was new
historically (or even now) allowed to have more than two parameters, (size, hint)
?
Any help on decoding would be appreciated.