| View previous topic :: View next topic |
| Author |
Message |
Rueschi Guest
|
Posted: Fri Feb 20, 2004 11:50 am Post subject: new TYPE[0] - legally? |
|
|
1) Is it safe to allocate an array of 0 objects?
2) If yes: has anyone experienced that there is
a bug in MSC 6 (12.00.8804) that does not allow
such allocations?
Rene
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Sat Feb 21, 2004 4:08 am Post subject: Re: new TYPE[0] - legally? |
|
|
Rueschi wrote:
| Quote: | 1) Is it safe to allocate an array of 0 objects?
|
Yes (the standard says so in section 5.3.4 paragraph 7).
| Quote: | 2) If yes: has anyone experienced that there is
a bug in MSC 6 (12.00.8804) that does not allow
such allocations?
|
I just tried the following code with that compiler:
#include <cassert>
int main()
{
assert(new int[0] != 0);
return 0;
}
It worked for me. Also I tried and failed to find any report of a bug
of this nature in the MS Knowledge Base. Are you doing something
different?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Allan Odgaard Guest
|
Posted: Sat Feb 21, 2004 4:21 am Post subject: Re: new TYPE[0] - legally? |
|
|
[email]rueschi (AT) GIquadrat (DOT) de[/email] (Rueschi) wrote in message news:<ed95d7a0.0402190626.6d2d2bd2 (AT) posting (DOT) google.com>...
| Quote: | 1) Is it safe to allocate an array of 0 objects?
|
Yes, section 5.3.4 paragraph 7 says that when the expression (i.e.
size) is zero, the allocation function is called to allocate an array
with no elements, and the returned pointer is non-null.
| Quote: | 2) If yes: has anyone experienced that there is
a bug in MSC 6 (12.00.8804) that does not allow
such allocations?
|
Nope... but then again, I don't use MSC :)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|