TITLE: new and sizes of zero (Newsgroups: comp.lang.c++.moderated, 29 Jan 97) GENTER: Rick Genter > Is > p = new void*[ 0 ]; > guaranteed to set p to a non-NULL value OLIVA: Alexandre Oliva The Dec'96 DWP states in [expr.new, paragraph 8] that a new expression involving a zero-sized array creates an array of no elements, and it returns a pointer whose value is different from any other pointer. GENTER: > ... (barring being out of memory, of course)? OLIVA: new expressions are no longer allowed to result [in] NULL. If no memory can be allocated, operator new should throw a bad_alloc exception. GENTER: > Reading Stroustrup it says that ::operator new(0) is guaranteed to return a > non-NULL value, but it says nothing about zero-dimensioned dynamic arrays. > Thanks in advance. OLIVA: ::operator new(size_t) is not used for arrays, although AFAIK, when Stroustrup wrote the book, ::operator new[](size_t) did not exist yet. Anyway, even for an array of no elements, the number of bytes requested to the allocation function may be non-zero. Anyway, even if the requested size is zero, a pointer that is different from any other pointer must be returned. [ Netspeak decoder ring: AFAIK = as far as i know BTW = by the way OTHO = on the other hand IMHO = in my humble opinion NB = noto bene ("note well") - adc ]