C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

new TYPE[0] - legally?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Rueschi
Guest





PostPosted: Fri Feb 20, 2004 11:50 am    Post subject: new TYPE[0] - legally? Reply with quote



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





PostPosted: Sat Feb 21, 2004 4:08 am    Post subject: Re: new TYPE[0] - legally? Reply with quote



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





PostPosted: Sat Feb 21, 2004 4:21 am    Post subject: Re: new TYPE[0] - legally? Reply with quote



[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.