new array of size 0 and delete...

consider this...

std::map<int,int> table; // any container of size ZERO.
// table.size() is zero.

A ** ptr = new A*[table.size()];
delete [] ptr;

One can pass any variable with value ZERO in the new call.
Is there any actual memory allocated to ptr... If yes, then what is the size of the chunck. Is there any probability of crash...?
Dynamically allocated zero-sized arrays are allowed so the code should work fine.
is dereferencing dynamically allocated zero-sized arrays, defined/undefined?
It's undefined.
Given that a zero sized array has no elements then dereferencing it is an error.
Topic archived. No new replies allowed.